In the earlier RC releases of Angular 2 I was able to inject the window object by adding
{provide: Window, useValue: window}
To the providers
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})