Reputation: 499
I think that ngAfterViewInit()
should be called after a component's view, and its children's views, are created. I tested this, and found that children's ngAfterViewInit()
s are called before the parent's ngAfterViewInit()
. Is it an expected behavior? I need a function in parent class which is called after ngAfterViewInit. How can I do this?
Regards
Upvotes: 0
Views: 1479
Reputation: 657741
Yes, this is expected behavior. ngAfterViewInit()
is called after the view is initialized. Children are part of the view, therefore it can't be called before childrens ngAfterViewInit()
.
You can try if ngAfterContentInit()
matches your need, but I'd reconsider your approach. For example use a shared service with an observable to notify the parent about the status of the children.
Upvotes: 1