In my Angular 2 application I provide the window object using what is described here: Angular2 - How to inject window into an angular2 service.
However the ngc compiler used for AOT returns several errors. First I had to change the way I provide the dependency (note the 'Window'):
@NgModule({
providers: [
{ provide: 'Window', useValue: window }
],
...
})
export class AppModule {}
And in my component (note the type 'any'):
@Component({ ... })
export default class MyComponent {
constructor (
@Inject('Window') private window: any
) {}
...
However I still get the following error thrown by the ngc compiler in my module ngfactory:
Property 'window' does not exist on type
Again everything is working fine with the tsc compiler.
In the end I fixed my issue by following exactly what is described here: http://juristr.com/blog/2016/09/ng2-get-window-ref/
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With