Angular · Senior · Question 2 of 75
Why would you call NgZone.runOutsideAngular() in a zone-based app?
this.zone.runOutsideAngular(() => {
window.addEventListener("mousemove", this.onMove);
});- ✓Correct answer: So high-frequency events or animation loops don't trigger change detection on every tick
- 2To run code in a Web Worker
- 3To make errors bypass the
ErrorHandler
Explanation
Thousands of mousemove or requestAnimationFrame callbacks would each trigger app-wide change detection (zone pollution). Re-enter with zone.run() only when the UI really needs an update.