How do you use ChangeDetectorRef in Angular?
ChangeDetectorRef allows you to manually control change detection:
- detectChanges(): Run change detection immediately.
- markForCheck(): Mark component to check in next cycle.
- detach(): Stop change detection for component.
- reattach(): Resume change detection.
✅ Example:
constructor(private cd: ChangeDetectorRef) {}
updateData() {
this.data = fetchNewData();
this.cd.detectChanges(); // manually trigger update
}