Question presented to candidate: "Name Angular's lifecycle hooks, tell me in what order they run for a parent with a child component, which ones run once and which run on every change detection pass, and how the newer render hooks and DestroyRef fit in."
What a strong answer should cover:
- The eight class hooks in order:
ngOnChanges,ngOnInit,ngDoCheck,ngAfterContentInit,ngAfterContentChecked,ngAfterViewInit,ngAfterViewChecked,ngOnDestroy; which are "once" and which are "every check". - Parent + child interleaving: the parent reaches its content hooks before the child is even constructed, and the parent
ngAfterViewInitruns only after the whole child subtree finished. - Destruction runs child first, and
DestroyRef.onDestroycallbacks run right after the matchingngOnDestroy. - The function-based render hooks (
afterNextRender,afterEveryRender) run after the whole application rendered, browser only. - With OnPush as the default in v22, a skipped component still gets
ngDoCheckfrom its parent, but nothing below it runs. - What each hook is for (inputs, init, projected content, own view, cleanup) and why
ngDoCheck/...Checkedhooks must be cheap.
Clarifying questions expected:
- "Do you want the class-based hooks only, or also the signal-era render hooks?"
- "Are the components OnPush (the v22 default) or Eager?"
Code / implementation expected: Optional β a parent and child that log every hook, or the order written out from memory.