The life cycle of a component

Angular manages the life cycle of a component. Angular takes care of creating and rendering the components and their children and destroying them before removing them from the DOM. Angular keeps track of the value of the component property value. The following are the life cycle events of an Angular component given in calling order:

  • OnChanges: This event is fired when a binding values changes. This method will have access to both the old value and the new value.
  • OnInit: This event is fired after the execution of the OnChanges event due to binding value changes.
  • DoCheck: This event is fired for every change detected, and developers can write custom logic to check for the property changed.
  • AfterContentInit: This event will be fired when the directive's content has been completely initialized.
  • AfterContentChecked: This event will be fired after a directive's content has been checked.
  • AfterViewInit: This event will be fired when the component's template has been completely initialized.
  • AfterViewChecked: This event will be fired after the component's template has been checked.
  • OnDestroy: This event will be fired before destroying the directive or component.

You can either implement all of these events or only the specific events that are required for your component.

..................Content has been hidden....................

You can't read the all page of ebook, please click here login for view all page.
Reset
18.116.51.117