ngOnInit(),ngAfterViewInit(),ngafterContentInit(),ngAfterViewChecked()和构造函数()之间有什么区别?我们如何在Angular 2中实现它们?
他们的目的和用途是什么?实施它们的所有方面都有用吗?
他们的目的和用途是什么?实施它们的所有方面都有用吗?
@H_404_9@
谢谢.@H_404_9@
解决方法
这些是生命周期钩子,您可以利用它们来执行操作和组件生命周期的不同时间.
@H_404_9@
官方角度文档中有关于该主题的优秀指南:https://angular.io/guide/lifecycle-hooks@H_404_9@
@H_404_9@
A component has a lifecycle managed by Angular.@H_404_9@
Angular creates it,renders it,creates and renders its children,
checks it when its data-bound properties change,and destroys it
before removing it from the DOM.@H_404_9@Angular offers lifecycle hooks that provide visibility into these key
life moments and the ability to act when they occur.@H_404_9@
official documentation中的下图描述了生命周期钩子的顺序:@H_404_9@