Dependency injection and change detection · core
Change detection: Zone.js and zoneless
Change detection re-reads template bindings and updates the DOM. With Zone.js Angular checks after any async task. Zoneless apps check only when told, for example by a signal.
Explain it out loud
Explain it out loud to an AI interviewer that follows up, and see where your answer is thin.
Practise by voiceThe notes
What you must know
- Change detection walks the component tree and updates the DOM where a bound value changed.
- Zone.js patches browser async APIs (events,
setTimeout, promises, XHR, fetch). When a task ends, NgZone tells Angular, which checks from the root. - That is simple, but it checks too often, adds bundle size and can be triggered by third-party code.
- New apps have been zoneless since v21 (facts.md). Zoneless needs a notification: a signal change read in a template,
markForCheck(), a template or host listener, or theasyncpipe. - Old code that relies on Zone.js still exists. A third-party widget that changes data from its own
addEventListenerstops updating when you go zoneless, because nothing tells Angular. - In development Angular runs a second check to find values that changed during the first.
- A runaway timer or
requestAnimationFrameloop in the Angular zone makes the app check on every tick: profile with Angular DevTools.
The red pen
Common traps: mistake → fix
Mistake: Angular polls the DOM on a timer
Fix: with Zone.js it checks after async tasks; zoneless checks after notifications.
Mistake: Zoneless means no change detection
Fix: it means change detection runs only when signalled.
Easy to hard
Questions interviewers ask, easy to hard
- What triggers change detection with Zone.js?
- What does zoneless change detection need to update the screen?
- A third-party chart makes the app slow all the time. What do you do?
- Why did a date picker stop updating after you removed Zone.js?
Explain it out loud
Explain it out loud to an AI interviewer that follows up, and see where your answer is thin.
Practise by voiceYour first interview is free
Sign up and start with a 15-minute interview with the full report, and an English conversation. No card needed.