Skip to content

Function: invokeInNgZone()

@flyze/lib-core-angular 1.0.0-alpha.34· latest

invokeInNgZone<VALUE>(ngZone): MonoTypeOperatorFunction<VALUE>

Defined in: projects/lib-core-angular/src/lib/rxjs/invoke-in-ng-zone.operator.ts:35

Re-enters the Angular zone at delivery, so an observable that emits outside the zone still renders under zone-based change detection.

An out-of-zone emission reaches the AsyncPipe, which calls markForCheck() - but that only marks the view, and the tick that would check it never comes because no zone event follows. The UI stays stale until an unrelated interaction. Typical producers: user-scripting runtimes and third-party libraries that escape the zone deliberately (gridster drag/resize callbacks, echarts continuations) and then emit through synchronous rxjs Subjects.

The zone is a parameter on purpose: it works both from injection contexts (invokeInNgZone(inject(NgZone))) and from Injector-based resolution (invokeInNgZone(this.injector.get(NgZone))), and it keeps the dependency visible at the call site.

Placement: apply it as the last operator before any sharing. With multiple async pipes on one stream, follow it with shareReplay({ bufferSize: 1, refCount: true }) so one emission enters the zone once and triggers one change detection cycle.

Zone-era bridge: under zoneless change detection (provideZonelessChangeDetection()) NgZone is a noop and this operator degrades to a pass-through - harmless but dead. Delete it from the pipe when the consuming application goes zoneless.

VALUE

NgZone

The zone to re-enter - the NgZone instance of the consuming application.

MonoTypeOperatorFunction<VALUE>

An operator that mirrors the source, delivering next, error and complete inside the Angular zone.