Question presented to candidate: "Explain the difference between afterRender and afterNextRender. Go a level deeper than 'once versus every time': what are the phases, why do they exist, and what does 'every render' actually mean in an application with many components?"
What a strong answer should cover:
afterNextRenderruns once;afterRender(renamedafterEveryRenderin v20, the only name in 22.2.3) runs after every application render.- "Every render" is application-wide: the callback runs even when only some unrelated component changed.
- The four phases in fixed order:
earlyRead,write,mixedReadWrite,read; the plain-callback form runs inmixedReadWrite; each phase receives the previous phase's return value. - Phases are scheduled across all components (all writes before all reads) to avoid layout thrashing; Angular cannot enforce correct use.
afterRenderEffectas the signal-driven variant that runs only when its dependencies change.- Browser only, injection context required, returns an
AfterRenderRefwithdestroy().
Clarifying questions expected:
- "Which Angular version? The old name only exists before v20."
- "Is the work a DOM read, a DOM write, or both?"
Code / implementation expected: Optional β a phased afterNextRender spec and an afterEveryRender read.