加入收藏 | 设为首页 | 会员中心 | 我要投稿 李大同 (https://www.lidatong.com.cn/)- 科技、建站、经验、云计算、5G、大数据,站长网!
当前位置: 首页 > 综合聚焦 > 服务器 > 安全 > 正文

angular – ngOnInit(),ngAfterViewInit(),ngafterContentInit()

发布时间:2020-12-17 06:52:01 所属栏目:安全 来源:网络整理
导读:ngOnInit(),ngAfterViewInit(),ngafterContentInit(),ngAfterViewChecked()和构造函数()之间有什么区别?我们如何在Angular 2中实现它们? 他们的目的和用途是什么?实施它们的所有方面都有用吗? 谢谢. 解决方法 这些是生命周期钩子,您可以利用它们来执行操
ngOnInit(),ngAfterViewInit(),ngafterContentInit(),ngAfterViewChecked()和构造函数()之间有什么区别?我们如何在Angular 2中实现它们?
他们的目的和用途是什么?实施它们的所有方面都有用吗?

谢谢.

解决方法

这些是生命周期钩子,您可以利用它们来执行操作和组件生命周期的不同时间.

官方角度文档中有关于该主题的优秀指南:https://angular.io/guide/lifecycle-hooks

A component has a lifecycle managed by Angular.

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.

Angular offers lifecycle hooks that provide visibility into these key
life moments and the ability to act when they occur.

official documentation中的下图描述了生命周期钩子的顺序:

enter image description here

(编辑:李大同)

【声明】本站内容均来自网络,其相关言论仅代表作者个人观点,不代表本站立场。若无意侵犯到您的权利,请及时与联系站长删除相关内容!

    推荐文章
      热点阅读