Lifecycle hooks in Angular
Angular components, directives have various life cycle events starting from their creation till the time they are destroyed. To handle those lifecycle events, Angular provides you the Lifecycle hooks to act on those events whenever they occur.
For Example, Angular provides you a hook "ngOnInit()" that Angular calls after creating the component. In this lifecycle hook, you can perform some task which you want to do after the component creation.
Angular only calls a directive/ component hook method if it is defined.
Lifecycle Hooks Sequence:
Angular calls lifecycle hooks in the following sequence:
- ngOnChanges()
- ngOnInit()
- ngDoCheck()
- ngAfterContentInit()
- ngAfterContentChecked()
- ngAfterViewInit()
- ngAfterViewChecked()
- ngOnDestroy()
0 Comments