← Back to Article List         
Component Lifecycle - Interview Questions

Component Lifecycle - Interview Questions

Published on 02 Oct 2026     2 min read Angular
Component Lifecycle - Interview Questions

Angular Lifecycle Hooks — Interview Quick Revision

1. What are Angular lifecycle hooks?

Lifecycle hooks are methods Angular calls at specific stages of a component/directive's lifecycle, such as creation, input changes, rendering, checking, and destruction.
Examples: ngOnInit(), ngOnChanges(), ngOnDestroy().

2. What is ngOnInit()?

ngOnInit() runs once after Angular initializes the component's inputs. It is commonly used for initialization logic and loading data.
ngOnInit() { this.loadProducts(); }

3. What is ngOnChanges()?

ngOnChanges() runs when an input property changes and receives a SimpleChanges object containing previous/current values.
ngOnChanges(changes: SimpleChanges) { }

4. What is ngDoCheck()?

ngDoCheck() runs during change detection and allows custom change-detection logic.
Use it carefully because it can execute frequently.

5. What is ngAfterContentInit()?

ngAfterContentInit() runs once after Angular initializes projected content passed through <ng-content>.
It is useful when working with ContentChild or ContentChildren.

6. What is ngAfterContentChecked()?

ngAfterContentChecked() runs after Angular checks the component's projected content.
It may run frequently, so avoid expensive operations inside it.

7. What is ngAfterViewInit()?

ngAfterViewInit() runs once after the component's view and child views are initialized.
It is commonly used when accessing ViewChild/ViewChildren.

8. What is ngAfterViewChecked()?

ngAfterViewChecked() runs after Angular checks the component's view and child views.
Avoid heavy logic because it can execute frequently.

9. What is ngOnDestroy()?

ngOnDestroy() runs just before Angular destroys a component or directive. It is used for cleanup such as timers, listeners, and manual subscriptions.
ngOnDestroy() { clearInterval(this.timer); }

10. What is the lifecycle hook execution order?

For initial creation, the main order is:
ngOnChanges → ngOnInit → ngDoCheck → ngAfterContentInit → ngAfterContentChecked → ngAfterViewInit → ngAfterViewChecked; finally ngOnDestroy when destroyed.

11. Constructor vs ngOnInit() — what is the difference?

Constructor: TypeScript class creation and dependency injection.
ngOnInit(): Angular lifecycle initialization after initial input values are set.

12. When should cleanup be performed in ngOnDestroy()?

Use ngOnDestroy() to clean up manual subscriptions, timers, event listeners, or other resources to prevent memory leaks.
Modern Angular can also use APIs such as takeUntilDestroyed() for automatic subscription cleanup.