Swiftorial Logo
Home
Swift Lessons
AI Tools
Learn More
Career
Resources

Angular FAQ: Top Questions

48. How to detect changes manually in Angular?

Use the ChangeDetectorRef service to trigger change detection manually. This is helpful in situations where Angular's automatic detection doesn't run.


constructor(private cd: ChangeDetectorRef) {}

someAsyncOp() {
  setTimeout(() => {
    this.data = 'updated';
    this.cd.detectChanges();
  });
}
        

You can also use markForCheck() when using OnPush strategy.