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);
});

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.

Further reading

Problem with a question

Angular · Senior · question 2

Test yourself

Take the Angular · Senior quiz: questions and options are shuffled, and you get a review of your mistakes at the end.

Take this quiz