ngOnInit(),ngAfterViewInit(),ngafterContentInit(),ngAfterViewChecked()和构造函数之间有什么区别? [英] What is the difference between ngOnInit(), ngAfterViewInit(), ngafterContentInit(), ngAfterViewChecked() and a constructor()?

查看:318
本文介绍了ngOnInit(),ngAfterViewInit(),ngafterContentInit(),ngAfterViewChecked()和构造函数之间有什么区别?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

ngOnInit (), ngAfterViewInit (), ngafterContentInit ()和 ngAfterViewChecked ( )和构造函数()?我们如何在Angular 2中实现它们? 它们的目的和用途是什么?在什么地方实施它们会很有用?

What is the difference between ngOnInit(), ngAfterViewInit(), ngafterContentInit(), ngAfterViewChecked() and a constructor()? How do we implement them in the Angular 2? What are their purposes and usages? Where all will it be useful for implementing them?

谢谢.

推荐答案

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

Those are life cycle hooks that you can tap into to perform operations and different times of a components life cycle.

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

There is an excellent guide on the topic in the official angular documentation: https://angular.io/guide/lifecycle-hooks

组件的生命周期由Angular管理.

A component has a lifecycle managed by Angular.

Angular创建,渲染,创建并渲染其子对象, 当其数据绑定属性更改时对其进行检查,并销毁它 在将其从DOM中删除之前.

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提供了生命周期挂钩,这些挂钩提供了对这些键的可见性 一生的时刻以及它们发生时的行动能力.

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

官方文档中的下图描述了生命周期挂钩的顺序:

The following diagram from the official documentation describes the order of lifecycle hooks:

这篇关于ngOnInit(),ngAfterViewInit(),ngafterContentInit(),ngAfterViewChecked()和构造函数之间有什么区别?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆