【发布时间】:2018-08-05 06:05:02
【问题描述】:
在非角度应用程序中,我们可以通过以下方式响应窗口调整大小事件:
window.onresize = function(event) {
console.log('changed');
};
但是我们不能在 Angular 应用程序中使用它,因为直接访问窗口对象是一种不好的做法。我们如何以“角度”的方式实现上述功能?
【问题讨论】:
标签: javascript angular
在非角度应用程序中,我们可以通过以下方式响应窗口调整大小事件:
window.onresize = function(event) {
console.log('changed');
};
但是我们不能在 Angular 应用程序中使用它,因为直接访问窗口对象是一种不好的做法。我们如何以“角度”的方式实现上述功能?
【问题讨论】:
标签: javascript angular
对于任何有兴趣的人:
@HostListener('window:resize', ['$event']) onResize(event) {
console.log(event.target.innerWidth;);
}
【讨论】: