[SOLVED] The life cycle of an Angular component

When developing an Angular application, it is important to understand how components work, including their life cycle. This lifecycle is managed by Angular, so it’s Angular that will create the component, render it, and finally destroy it when necessary.

  • ngOnChanges : It is called when an input is defined or modified from the outside. The status of changes to the inputs is provided as a parameter.
  • ngOnInit : it is called only once and allows the initialization of the component, whether heavy or asynchronous (we do not touch the constructor for that)
  • ngDoCheck : It is called after each detection of changes.
  • ngAfterContentInit : It is called that after the external content is projected into the component (transclusion).
  • ngAfterContentChecked : It is called each time an external content check (transclusion) is made.
  • ngAfterViewInit : It is called when the component view as well as that of its children are initialized.
  • ngAfterViewChecked : It is called after each check of component views and child component views.
  • ngOnDestroy : It is called just before the component is destroyed by Angular.

Note that the ngAfterContentInit, ngAfterContentChecked, ngAfterViewInit and ngAfterViewChecked methods are exclusive to components, while all others are also exclusive to directives.

For more information click here

people found this article helpful. What about you?