window is undefined when used as useValue provider with Angular 4 AoT
问题 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