每当组件可见时发生的事件

编程入门 行业动态 更新时间:2024-10-27 17:15:06
本文介绍了每当组件可见时发生的事件的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧! 问题描述

当我的组件可见时,Angular2中是否有办法触发事件? 它放在一个tabcontrol中,我希望在用户切换时得到通知.我希望我的组件触发一个事件.

Is there a way in Angular2 to have an event fired when my component becomes visible? It is placed in a tabcontrol and I want to be notified when the user switches. I'd like my component to fire an event.

推荐答案

我最后做的(虽然不是很漂亮,但是在我没有更好的方法时可以工作...)是使用ngAfterContentChecked()回调并自己处理更改.

What I finally did (which is not very beautiful but works while I don't have a better way to do it...) is to use the ngAfterContentChecked() callback and handle the change myself.

@ViewChild('map') m; private isVisible: boolean = false; ngAfterContentChecked(): void { if (this.isVisible == false && this.m.nativeElement.offsetParent != null) { console.log('isVisible switched from false to true'); this.isVisible = true; this.Refresh(); } else if (this.isVisible == true && this.m.nativeElement.offsetParent == null) { console.log('isVisible switched from true to false'); this.isVisible = false; } }

更多推荐

每当组件可见时发生的事件

本文发布于:2023-11-06 16:15:51,感谢您对本站的认可!
本文链接:https://www.elefans.com/category/jswz/34/1564183.html
版权声明:本站内容均来自互联网,仅供演示用,请勿用于商业和其他非法用途。如果侵犯了您的权益请与我们联系,我们将在24小时内删除。
本文标签:组件   发生   事件

发布评论

评论列表 (有 0 条评论)
草根站长

>www.elefans.com

编程频道|电子爱好者 - 技术资讯及电子产品介绍!