Performance: Default change detection strategy
MEDIUM IMPACT
This affects how often Angular checks and updates the UI, impacting interaction responsiveness and CPU usage.
import { Component, ChangeDetectionStrategy } from '@angular/core'; @Component({ selector: 'app-root', template: `<child-comp></child-comp>`, changeDetection: ChangeDetectionStrategy.OnPush }) export class AppComponent {} // OnPush strategy limits checks to input changes and events inside component
import { Component, ChangeDetectionStrategy } from '@angular/core'; @Component({ selector: 'app-root', template: `<child-comp></child-comp>`, changeDetection: ChangeDetectionStrategy.Default }) export class AppComponent {} // Default strategy triggers change detection for all components on every event
| Pattern | DOM Operations | Reflows | Paint Cost | Verdict |
|---|---|---|---|---|
| Default change detection | Checks all components every event | Triggers multiple reflows if many updates | High paint cost if many changes | [X] Bad |
| OnPush change detection | Checks only changed components | Minimal reflows | Lower paint cost | [OK] Good |