How to determine all the angular 2 components have been rendered?

半腔热情 提交于 2019-12-11 07:36:34

问题


Is there an angular event which will be triggered when all the Angular2 components have finished rendering?

For jQuery, we can use

$(function(){ ... })

However, with Angular2, when the domready event is triggered, the html contains angular component tags only. And after each component finished rendering, the domready event will be triggered again & again.

What we need is a final event when all the angular components have finished rendering.


回答1:


Have you tried ngAfterViewInit on the root AppComponent? I'm sure all the components have been rendered by then. This is a hook that angular calls after it creates all the component's child views.




回答2:


you may check ngAfterViewInit applied on the root component.

ngAfterViewInit Respond after Angular initializes the component's views and child views. Called once after the first ngAfterContentChecked.

Read more about it here.

Hope this helps!!



来源:https://stackoverflow.com/questions/40383006/how-to-determine-all-the-angular-2-components-have-been-rendered

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!