[英]Angular 14 Resize Observable not triggering
It is not triggering at all, the console log doesn't print and the this.widht doesn't change.它根本不触发,控制台日志不打印并且 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);
}
I think you need a ViewChild to populate this.host ElementRef: https://medium.com/@anooprvarrier/angular-elementref-interface-c826cd5db732我想你需要一个 ViewChild 来填充 this.host ElementRef: https://medium.com/@anooprvarrier/angular-elementref-interface-c826cd5db732
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.