【问题标题】:Angular, how to react to a window resize event [duplicate]Angular,如何对窗口调整大小事件做出反应[重复]
【发布时间】:2018-08-05 06:05:02
【问题描述】:

在非角度应用程序中,我们可以通过以下方式响应窗口调整大小事件:

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

但是我们不能在 Angular 应用程序中使用它,因为直接访问窗口对象是一种不好的做法。我们如何以“角度”的方式实现上述功能?

【问题讨论】:

标签: javascript angular


【解决方案1】:

对于任何有兴趣的人:

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

致谢:Angular window resize event

【讨论】:

  • 但这会调用监听器数十次。需要油门功能。
猜你喜欢
  • 2017-07-13
  • 2018-12-13
  • 1970-01-01
  • 1970-01-01
  • 2014-04-06
  • 1970-01-01
  • 1970-01-01
  • 2010-10-13
相关资源
最近更新 更多