Dynamic module/service configuration and AOT
问题 I need to have some Angular services configured dynamically, depending on a runtime switch. In days before AOT, I got it to work using the following code: @NgModule({ imports: [HttpModule], providers: [] }) export class MyModule { static forRoot(config: MyConfiguration): ModuleWithProviders { return { ngModule: MyModule, providers: [ SomeService, { provide: SomeOtherService, useFactory: (some: SomeService, http: Http) => { switch (config.type) { case 'cloud': return new SomeOtherService(new