35

I am using a Angular plugin on data table. The container of the data table is resizable, while through the doc I learned that the data table it self will resize when there is a window resize event. In jQuery I know there is a $(window).trigger() but I don't know how to do that in angular.

My question is: in parent angular directive, how do I trigger that window resize event?

1 Answer 1

75

You can trigger window.resize event by

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

And for listening to window.resize, use HostListener as below example:

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

live demo

Sign up to request clarification or add additional context in comments.

5 Comments

Thanks for the answer. Is this piece of code listening to the window.resize event?
@Zanecat yeah, it is. you can confirm by change the size of the browser window. for the plunker demo, remember to open the console to see the message. :-)
Well, but I want to trigger this event rather than listen to it.
@Zanecat well, sorry for misunderstood your question, I have add what you want to my answer.
Thanks that helps a lot.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.