fbpx

24 Apr /Get In the Zone

Posted by Steve Gilliam

Using Zones is a great way to escape Angular’s change detection and speed up performance. However, when a 3rd party library uses them, it can cause some confusion and/or unexpected results (Any resemblance to actual persons or events is purely coincidental).

ChangeDetectorRef allows you to manually force change detection and be on your merry way.

import { ChangeDetectorRef } from '@angular/core';
...
export class Zoning {

     constructor(private changeDetector: ChangeDetectorRef) {}
...
    this.codeOutsideOfZone = true;

    // forces change detection
    this.changeDetector.detectChanges();
...
}