typescript Angular 14调整大小可观察到未触发

xzabzqsa  于 2023-01-14  发布在  TypeScript
关注(0)|答案(1)|浏览(117)

它根本不会触发,控制台日志不会打印,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);
}

相关问题