I tried to put the following code to get a window object in angular 2:
@Component({
selector: 'app-slider',
templateUrl: './slider.component.html',
styleUrls: ['./slider.component.css'],
providers: [
SliderService,
{ 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