它根本不会触发,控制台日志不会打印,this.widht也不会更改。
constructor(private host: ElementRef, private zone: NgZone) {}
public ngOnInit(): void {
this.observer = new ResizeObserver(entries => {
this.zone.run(() => {
this.width$.next(entries[0].contentRect.width);
console.log('width', width);
});
});
this.observer.observe(this.host.nativeElement);
}
1条答案
按热度按时间f4t66c6m1#
我认为您需要一个ViewChild来填充this.host元素引用:https://medium.com/@anooprvarrier/angular-elementref-interface-c826cd5db732