get angular width 1

get angular width

// to get it on init:
public innerWidth: any;
ngOnInit() {
    this.innerWidth = window.innerWidth;
}

// if you wanna keep it updated on resize:
@HostListener('window:resize', ['$event'])
onResize(event: any) {
  this.innerWidth = window.innerWidth;
}

Here is what the above code is Doing:
1. We’re using the @HostListener decorator to listen for the window:resize event.
2. We’re passing the event to the onResize() method.
3. We’re setting the innerWidth property to the window’s innerWidth property.

Similar Posts