How to trigger a window resize event in Angular

I am using an Angular plugin in a data table. The container of the data table resizes, and through the document I found out that the data table that it will change when there is a window resize event. In jQuery, I know what it is $(window).trigger(), but I don’t know how to do it in angular.

My question is: in the Angular parent directive, how do I trigger a window resize event?

+4
source share
1 answer

You can fire the event window.resizeon

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

And to listen window.resizeuse HostListener as below:

@HostListener('window:resize', ['$event'])
sizeChange(event) {
  console.log('size changed.', event);
}

plunger demonstration

+8
source

Source: https://habr.com/ru/post/1682813/


All Articles