Member-only story
Lifecycle Hooks in Angular
Angular’s lifecycle hooks are methods in Angular components and directives that allow you to tap into key moments in the lifecycle of a component or directive. Below is a description of the main lifecycle hooks with their execution order and a graph to illustrate their flow:
Key Lifecycle Hooks in Angular
ngOnChanges:
- Triggered when the input properties of a component or directive are changed.
- Receives a
SimpleChangesobject containing the previous and current values of the bound inputs.
2. ngOnInit:
- Called once, after the first
ngOnChanges. - Used for initialization logic that requires input properties to be set.
3. ngDoCheck:
- Called during every change detection run, after
ngOnChangesandngOnInit. - Used to detect changes that Angular does not.
4. ngAfterContentInit:
Called once after the content (e.g., <ng-content>) is projected into the component.
- Used for logic that depends on projected content.
5. ngAfterContentChecked:
Called after every check of the projected content.
- Used for logic that depends on content changes.
6. ngAfterViewInit:









