Search⌘ K

Component Lifecycle Hooks

Explore the various lifecycle phases of Angular components and how to use lifecycle hooks such as ngOnInit, ngOnChanges, and ngOnDestroy. Understand when these hooks execute and how they help manage component creation, updates, and destruction effectively within your application.

A component grows and goes through multiple phases throughout its life. Using and controlling these phases using lifecycle hooks helps you get a better hold of your application.

The component gets created, renders, renders its children, makes changes and gets destroyed. And this lifecycle is split into multiple phases that are linked to the component or the children of the component.

Constructor

A constructor is invoked when Angular creates a component using the new keyword in the class.

ngOnInit

This is invoked when the component initializes and gets the data.

ngOnchanges

...