简体   繁体   English

ngIf 对 ngAterViewInit 的影响

[英]Effect of ngIf on ngAterViewInit

I am emitting an event in ngAfterViewInit lifecycle hook, and listening to that event in another component using ComponentRef.我在 ngAfterViewInit 生命周期钩子中发出一个事件,并使用 ComponentRef 在另一个组件中监听该事件。 It works well until I use ngIf on the parent component.在我在父组件上使用 ngIf 之前,它运行良好。

So, what is this effect of ngIf on Angular life cycle hooks?那么,ngIf 对 Angular 生命周期钩子的这种影响是什么?

For now, I am setting its visibility to hidden but want to use ngIf.现在,我将其可见性设置为隐藏但想使用 ngIf。

ngIf is removing the component from the dom, and so must the child component would also be removed, If you only want to hide it use [hidden]="true" attribute. ngIf正在从 dom 中删除组件,因此子组件也必须被删除,如果您只想隐藏它,请使用[hidden]="true"属性。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM