打字稿:2.2.0 Angular:4.0
我试图通过使用确保ConfigService在应用程序启动之前初始化对象APP_INITIALIZER.我发现了很多如何做到这一点的例子,但是他们似乎没有延迟应用程序的初始化.以下是我尝试实施的一些示例.
https://github.com/angular/angular/issues/9047 https://gist.github.com/fernandohu/122e88c3bcd210bbe41c608c36306db9 Angular2 APP_INITIALIZER不一致
这是我的NgModule课
export function init(config: ConfigService) {
return () => {
config.load();
};
}
@NgModule({
declarations: [
AppComponent
],
imports: [
BrowserModule,
FormsModule,
HttpModule,
AppRoutingModule
],
providers: [
{
'provide': APP_INITIALIZER,
'useFactory': init,
'deps': [ConfigService],
'multi': true
},
ConfigService
],
bootstrap: [AppComponent]
})
export class AppModule {
}
Run Code Online (Sandbox Code Playgroud)
这是ConfigService班级
@Injectable()
export class ConfigService {
private config: ApplicationConfiguration;
get apiRoot() {
return this.getProperty('apiRoot'); // <--- THIS GETS …Run Code Online (Sandbox Code Playgroud)