http://plnkr.co/edit/yhQQZxTxB8ZVFysqO6lP?p=preview
如何确保在加载AppComponent之前解析我的AuthService?
0000 61 62 63 64
0010 71 72 73 74
答案 0 :(得分:0)
您可以使用APP_INITIALIZER令牌来提供您的authFactory:
//main entry point
import {bootstrap} from '@angular/platform-browser-dynamic';
import {Http,HTTP_PROVIDERS} from '@angular/http';
import {App} from './app';
import {AuthService} from './auth.service';
import {provide, enableProdMode, APP_INITIALIZER} from '@angular/core';
export function authFactory(auth: AuthService){
return auth.login()
}
bootstrap(App, [
HTTP_PROVIDERS,
{
provide: APP_INITIALIZER,
useFactory: (auth),
deps: [AuthService],
multi: true
}
]).catch(err => console.error(err));