简体   繁体   中英

Effect of ngIf on ngAterViewInit

I am emitting an event in ngAfterViewInit lifecycle hook, and listening to that event in another component using ComponentRef. It works well until I use ngIf on the parent component.

So, what is this effect of ngIf on Angular life cycle hooks?

For now, I am setting its visibility to hidden but want to use 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.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

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