6

In a non angular application we can respond to window resize events with the following:

  window.onresize = function(event) {
    console.log('changed');
  };

However we can't use this in angular applications since it's a bad practice to directly access the window object. How would we implement the above functionality in the 'angular' way?

Willem van der Veen
  • 33,665
  • 16
  • 190
  • 155

1 Answers1

6

For anyone who is interested:

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

Credits to: Angular window resize event

Willem van der Veen
  • 33,665
  • 16
  • 190
  • 155