Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Angular 2 AOT - Property 'window' does not exist on type

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.

like image 834
j3r6me Avatar asked Sep 04 '26 06:09

j3r6me


1 Answers

In the end I fixed my issue by following exactly what is described here: http://juristr.com/blog/2016/09/ng2-get-window-ref/

like image 190
j3r6me Avatar answered Sep 07 '26 01:09

j3r6me



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!