How to Inject Window into Angular 2.1.0
Try with:
@NgModule({
declarations: [...],
imports: [...],
providers: [
{ provide: "windowObject", useValue: window}
]
})
export class HomeModule {}
in your component:
constructor(@Inject("windowObject") window: Window})
In order for it to work with AOT you need to do useFactory instead of useValue:
export function windowFactory() {
return window;
}
module:
providers: [
{ provide: 'window', useFactory: windowFactory }
]
component:
constructor(@Inject('window') window: Window})