Quantcast
Channel: Angular window resize event - Stack Overflow
Viewing all articles
Browse latest Browse all 20

Answer by abedfar for Angular window resize event

$
0
0

Below code lets observe any size change for any given div in Angular.

<div #observed-div></div>

then in the Component:

oldWidth = 0;oldHeight = 0;@ViewChild('observed-div') myDiv: ElementRef;ngAfterViewChecked() {  const newWidth = this.myDiv.nativeElement.offsetWidth;  const newHeight = this.myDiv.nativeElement.offsetHeight;  if (this.oldWidth !== newWidth || this.oldHeight !== newHeight)    console.log('resized!');  this.oldWidth = newWidth;  this.oldHeight = newHeight;}

Viewing all articles
Browse latest Browse all 20

Trending Articles



<script src="https://jsc.adskeeper.com/r/s/rssing.com.1596347.js" async> </script>