angular2-aot

window is undefined when used as useValue provider with Angular 4 AoT

风流意气都作罢 提交于 2019-11-27 07:00:48
问题 When Angular 4.0.2 application is compiled ahead-of-time, and the provider is defined as useValue import { OpaqueToken, Provider } from '@angular/core'; export const windowToken = new OpaqueToken('window'); export const windowProvider = { provide: windowToken, useValue: window }; and used like @NgModule({ providers: [windowProvider], ... }) export class AppModule {} it compiles ok but results in window being undefined when injected as constructor(@Inject(windowToken) window) { window

Pass config data using forRoot

穿精又带淫゛_ 提交于 2019-11-26 11:59:31
问题 I am trying to pass config data into a custom library in Angular. In the users application , they will pass some config data to my library using forRoot // Import custom library import { SampleModule, SampleService } from \'custom-library\'; ... // User provides their config const CustomConfig = { url: \'some_value\', key: \'some_value\', secret: \'some_value\', API: \'some_value\' version: \'some_value\' }; @NgModule({ declarations: [...], imports: [ // User config passed in here