Skip to content

Instantly share code, notes, and snippets.

@metanav
Last active August 8, 2019 01:54
Show Gist options
  • Star 2 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save metanav/44341d6be84724d3b2c2dea183727349 to your computer and use it in GitHub Desktop.
Save metanav/44341d6be84724d3b2c2dea183727349 to your computer and use it in GitHub Desktop.
A RxJS pipeable operator which let the observables to enter into angular zone so that the change detection works properly.
import { NgZone } from '@angular/core';
import { Observable } from 'rxjs/Observable';
export function enterZone(zone: NgZone) {
return <T>(source: Observable<T>) =>
new Observable<T>(observer =>
source.subscribe({
next: (x) => zone.run(() => observer.next(x)),
error: (err) => observer.error(err),
complete: () => observer.complete()
})
);
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment