在您的服务中:
constructor(public http: Http) { Observable.interval(30 * 60 * 1000) .switchMap(this.http.get(`...`)) .map(res => res.json()) .subscribe(res => this.check(res)) } private check(res: <Meter[]>) { // check whether to notify the user }
然后在你的模块中使用它(你不需要在任何地方注入服务):
providers: [ { provide: APP_INITIALIZER, use: GetUnitsProvider, deps: [Http], multi: true } ],