我使用以下命令来设置容器的大小:
ngOnInit() {
this.innerWidth = document.getElementById("Cont").clientWidth;
this.containerWidth = this.innerWidth;
console.log("init");
}
@HostListener('window:resize',['$event'])
onResize(event) {
this.innerWidth = document.getElementById("Cont").clientWidth;
this.containerWidth = this.innerWidth;
}
当我加载页面时,容器比窗口大,因此我必须滚动,在窗口调整大小后,一切都按预期工作,不再需要滚动。有趣的是,我在控制台中看到他的消息“ init”,这意味着代码已执行。
为什么容器在init上没有大小?
谢谢!