Advertisement
Beginner Angular, Zoneless Change Detection & Zone.js

What is Zone.js, and what role does it traditionally play in Angular applications?

Short answer

Zone.js is a library that Angular has historically relied on to automatically detect when something in your application might have changed, such as after a click event, a timer, or an HTTP response, and it then triggers Angular's change detection so the screen updates to match…

Save Angular mock interview
Advertisement
AModel answer
Zone.js is a library that Angular has historically relied on to automatically detect when something in your application might have changed, such as after a click event, a timer, or an HTTP response, and it then triggers Angular's change detection so the screen updates to match the new data.
// polyfills.ts (traditional setup)
import 'zone.js';

// Angular patches async APIs like setTimeout,
// addEventListener, and Promises so it knows when to check for changes
Real-world example
A traditional Angular app updates its screen automatically after a button click handler changes a variable, without the developer manually telling Angular to refresh anything, because Zone.js detected the event and triggered change detection behind the scenes.
Likely follow-ups
  • What kinds of problems can Zone.js patching cause in an application?
  • Why would a team want to remove Zone.js from their project?
Related topics