Angular组件不拾取手动触发的Windows调整大小事件
有一个在调整窗口大小时重新渲染的组件(并且效果很好)。但是,页面上还有一些其他组件会导致元素出现/消失。每当可用空间发生变化时,我的组件就需要重新渲染。
由于此组件仅在应用程序中出现一次,因此我认为监听这样的窗口大小调整事件是安全的...
@HostListener('window:resize') // re-render if window is resized
private render() {
// code that causes the contents of the component to re-render
}
这部分有效。对于折叠和展开页面区域的其他同级组件,我想我可以像这样调用 windows.dispatchEvent ...
toggleRightSidebar() {
window.dispatchEvent(new Event('resize'));
this.settingsButtonClicked.emit();
}
但是具有 @HostListener 的同级组件不会检测到以这种方式触发的窗口调整大小事件。
我错过了什么吗?
Have a component that re-renders when the window is resized (and this works well). However, there are some other components on the page that cause elements to appear/disappear. My component needs to re-render whenever the available space changes.
As this component only appears once in the app, I thought it would be safe to listen to window resize events like this...
@HostListener('window:resize') // re-render if window is resized
private render() {
// code that causes the contents of the component to re-render
}
This part works. For the other sibling components that collapse and expand areas of the page, I thought I could just call windows.dispatchEvent like this...
toggleRightSidebar() {
window.dispatchEvent(new Event('resize'));
this.settingsButtonClicked.emit();
}
But the sibling component that has the @HostListener doesn't detect a windows resize event triggered in this manner.
Am I missing something?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论