Skip to main content

How does Angular track changes to properties in a component?

Angular tracks changes to a component's properties using the change detection mechanism, which works together with zone.js:

  1. zone.js intercepts asynchronous operations (timers, DOM events, HTTP requests) and notifies Angular that something may have changed.
  2. Angular runs a component check (change detection), traversing the component tree from the root down.
  3. For each property, Angular compares the old and new value. If it has changed, the template where that property is used gets updated.
  4. Optionally, you can control the check strategy through changeDetection (Default or OnPush) to optimize performance.

This way, Angular automatically synchronizes the component's data and the interface without manual intervention.

Short Answer

Interview ready
Premium

A concise answer to help you respond confidently on this topic during an interview.