What is the order of Angular lifecycle hooks?
Assesses fundamental understanding of Angular conventions, runtime behavior, and memory/performance considerations.
Hiring managers look for precision, avoidance of ambiguous jargon, and ability to explain trade-offs under real production conditions.
Angular calls lifecycle hooks in a defined order. The constructor runs first and should only inject dependencies. Then ngOnChanges fires whenever a bound input changes, before ngOnInit, which runs once after the first ngOnChanges. After that comes ngOnDestroy. In between, ngOnDestroy comes after view checks: specifically ngOnInit, then ngDoCheck on every change-detection run, followed by ngAfterContentInit and ngAfterContentChecked for projected content, then ngAfterViewInit and ngAfterViewChecked for the component's own view. ngOnDestroy runs once just before the component is removed and is where you unsubscribe, clear timers and detach listeners.
Order matters: ViewChild results are only available in ngAfterViewInit unless the query is static: true. Child views are initialised before the parent's ngAfterViewInit, so the parent hook runs last. Implement the typed interfaces such as OnInit for safety and clarity.
Candidate Response Strategy & Interview Tips
- Start with a concise one-sentence summary: Deliver a direct, confident answer first before expanding into nuances.
- Demonstrate real-world trade-offs: Discuss where this approach excels and when you would avoid it in production systems.
- Discuss complexity & edge cases: Proactively explain time/space complexity or boundary conditions (null values, scale limits).
- Prepare for interviewer follow-ups: Technical hiring panels frequently probe deeper into concurrency, backward compatibility, or alternative libraries.