In our Angular app we need to load config settings from the server before initializing the app.
Using APP_INITIALIZER
as such works great:
export function loadConfig(config: ConfigService) => () => config.load()
@NgModule({
declarations: [AppComponent],
imports: [BrowserModule,
routes,
FormsModule,
HttpModule],
providers: [
ConfigService,
{
provide: APP_INITIALIZER,
useFactory: loadConfig,
deps: [ConfigService],
multi: true
}
],
bootstrap: [AppComponent]
})
export class AppModule {
}
I then extended ErrorHandler to create a GlobalErrorHandler and wanted to tell Angular to use our GlobalErrorHandler, so I provided the ErrorHandler and told Angular to use the class GlobalErrorHandler.
providers: [
ConfigService,
{
provide: APP_INITIALIZER,
useFactory: loadConfig,
deps: [ConfigService],
multi: true
},
{
provide: ErrorHandler,
useClass: GlobalErrorHandler
}
]
GlobalErrorHandler needs information from the config settings and I need to instantiate GlobalErrorHandler AFTER the setting's promise is resolved. In the set up above, GlobalErrorHandler is created before my call is made to the server for the configuration values.
How can I load the configuration values from the server, and THEN instantiate the GlobalErrorHandler and use the configuration values?