What is Change detection and type of change detection?

Anil Kumar
Mar 4, 2024

--

Angular can detect changes when component data changes, and then automatically re/render the view to reflect that change whole mechanism science is called as Angular Change detection.

API Calls, data received in events within component/ service etc, mouse events(click, scroll) keyboard events, timer function setTimeOut and interval.

If there is any change means above events occur By default angular perform top to bottom check on angular each component / other component, angular provide encapsulation so each component with its own change detector to detect and update DOM and keep in sync.

Type of Change Detection —

  1. Default
  2. onPush
import { ChangeDetectionStrategy, Component } from '@angular/core';

@Component({
selector: 'app-root',
standalone: true,
changeDetection: ChangeDetectionStrategy.OnPush
})

--

--