I have an angular2 application (RC6 version) where some important global parameters are loaded from the configuration file using a service that collects this file at startup:
@NgModule({
imports: [ BrowserModule, FormsModule, HttpModule, AppRoutes, SomeCustomModule ],
declarations: [ AppComponent ]
providers: [
ConfigurationService,
{
provide: APP_INITIALIZER,
useFactory: (config: ConfigurationService) => () => {
return config.load().then(configParams=> { return true;});
},
deps: [ConfigurationService, HttpModule],
multi: true
}
],
bootstrap:[ AppComponent ]
})
export class AppModule { }
As shown in this snippet, I use what I call ConfigurationService , which, through an http call, reads the configuration file and returns some parameters (as a promise). If everything goes well, the application loads perfectly and these configuration options are available in all submodules, etc.
, , , ? ( , AppComponent -, , ). "" /, ?