Issue
I am looking for a concept to implement the following case:
I have a parent search component that has some components as view children / content children for displaying facets and search results. I now want to trigger a search when the application has finished loading so the user does not see an empty page.
My problem now is that I cannot find a lifecycle hook that fits my needs. The facets / search results subscribe to the search results in their respective ngOnInit. So I need a hook that gets called after all child components had finished initializing.
I have tried the following hooks on the parent component
- ngAfterContentInit: this gets called before ngOnInit is called on the children
- ngAfterViewInit: this one works but after the search results return the view of the children gets updated which leads to an error since actions that manipulate the view are not allowed in ngAfterViewInit
Any Idea how to tackle this problem? To me it seems I do not grasp something fundamental here.
Cheers
Tom
Solution
I ended up using the ngAfterViewInit() hook in the following way:
ngAfterViewInit(){
//stuff that doesn't do view changes
setTimeout(_=> this.methodThatKicksOffAnotherRoundOfChanges());
}
This should be safe to use compared to other invocations of setTimeout where an actual time is set, since it should start instantly (and just affect the threading/context behaviour)
Answered By - Tom
0 comments:
Post a Comment
Note: Only a member of this blog may post a comment.