这是最简单的解决方案,Service没有/ 也没有Observer:将全局变量放在文件中,然后导出它们。//// ===== File globals.ts //'use strict';export const sep='/';export const version: string="22.2.2"; 要在另一个文件中使用全局变量,请使用以下import语句: import * as myGlobals from './globals';例:// // ===== File heroes.component.ts //import {Component, OnInit} from 'angular2/core';import {Router} from 'angular2/router';import {HeroService} from './hero.service';import {HeroDetailComponent} from './hero-detail.component';import {Hero} from './hero';import * as myGlobals from './globals'; //<==== this oneexport class HeroesComponent implements OnInit { public heroes: Hero[]; public selectedHero: Hero; // // // Here we access the global var reference. // public helloString: string="hello " + myGlobals.sep + " there"; ... } }