angular resize event code example

Example 1: typescript on window resize

@HostListener('window:resize', ['$event'])
onResize(event) {
  event.target.innerWidth;
}

Example 2: emit resize event in angular

window.dispatchEvent(new Event('resize'));

Example 3: div resize event typescript

resizeObservable$: Observable<Event>
resizeSubscription$: Subscription

ngOnInit() {
    this.resizeObservable$ = fromEvent(window, 'resize')
    this.resizeSubscription$ = this.resizeObservable$.subscribe( evt => {
      console.log('event: ', evt)
    })
}

Example 4: how to run resize event only on client side angular

<div (window:resize)="onResize($event)"