[Fixed] How can I use a window object in Angular 2?


I tried to put the following code to get a window object in angular 2:

          selector: 'app-slider',
          templateUrl: './slider.component.html',
          styleUrls: ['./slider.component.css'],
          providers: [
            { provide: "windowObject", useValue: window}
        export class SliderComponent implements OnInit {
          sliderList: Slider[] = [];
          constructor( private _sliderservice:SliderService, @Inject("windowObject") private _window:window ) { }

Unfortunately it does not work.


You don’t need a provider for that. window is a global object and is accessible directly in your class

Leave a Reply

(*) Required, Your email will not be published