Performance: Triggering detection manually
MEDIUM IMPACT
This affects how quickly Angular updates the UI after data changes, impacting interaction responsiveness and visual stability.
import { ChangeDetectorRef } from '@angular/core'; constructor(private cdr: ChangeDetectorRef) {} updateData(newData: any) { this.data = newData; this.cdr.detectChanges(); }
setTimeout(() => { this.data = newData; }); // relies on Angular zone to detect changes
| Pattern | DOM Operations | Reflows | Paint Cost | Verdict |
|---|---|---|---|---|
| Automatic zone-triggered detection | Many checks on all components | Multiple reflows if many changes | Higher paint cost due to frequent updates | [X] Bad |
| Manual detectChanges call | Checks only updated components | Single reflow per update | Lower paint cost with targeted updates | [OK] Good |