What does zone.js do when the application starts?
In Angular, zone.js is a library that tracks asynchronous operations in the application and helps Angular automatically run change detection after they complete.
Key points
- Intercepting asynchronous events
zone.js"wraps" timers (setTimeout,setInterval), promises, HTTP requests, and DOM events.- When such operations complete, Angular knows it needs to update the interface.
- Automatically running change detection
- After every asynchronous event, Angular automatically checks the components and updates the DOM.
- This frees the developer from having to call
detectChanges()manually.
- When the application starts
zone.jsis picked up inmain.tsthrough theimport 'zone.js'import.- All the application's asynchronous tasks fall inside the "zone," and Angular tracks their completion.
In other words, zone.js provides automatic change detection after asynchronous operations, which lets the interface always stay up to date without manual intervention.
Short Answer
Interview readyPremium
A concise answer to help you respond confidently on this topic during an interview.