我尝试输入以下代码以获取角度 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 ) { }
不幸的是,它不起作用。