• Overview
@angular/core

NgZone

Class

An injectable service for executing work inside or outside of the Angular zone.

  
    class NgZone {}
  
  

hasPendingMacrotasks

boolean

hasPendingMicrotasks

boolean

isStable

boolean

Whether there are no outstanding microtasks or macrotasks.

onUnstable

Notifies when code enters Angular Zone. This gets fired first on VM Turn.

onMicrotaskEmpty

Notifies when there is no more microtasks enqueued in the current VM Turn. This is a hint for Angular to do change detection, which may enqueue more microtasks. For this reason this event can fire multiple times per VM Turn.

onStable

Notifies when the last onMicrotaskEmpty has run and there are no more microtasks, which implies we are about to relinquish VM turn. This event gets called just once.

onError

Notifies that an error has been delivered.

run

T

Executes the fn function synchronously within the Angular zone and returns value returned by the function.

Running functions via run allows you to reenter Angular zone from a task that was executed outside of the Angular zone (typically started via runOutsideAngular).

Any future tasks or microtasks scheduled from within this function will continue executing from within the Angular zone.

If a synchronous error happens it will be rethrown and not reported via onError.

@paramfn(...args: any[]) => T
@paramapplyThisany
@paramapplyArgsany[] | undefined
@returnsT

runTask

T

Executes the fn function synchronously within the Angular zone as a task and returns value returned by the function.

Running functions via runTask allows you to reenter Angular zone from a task that was executed outside of the Angular zone (typically started via runOutsideAngular).

Any future tasks or microtasks scheduled from within this function will continue executing from within the Angular zone.

If a synchronous error happens it will be rethrown and not reported via onError.

@paramfn(...args: any[]) => T
@paramapplyThisany
@paramapplyArgsany[] | undefined
@paramnamestring | undefined
@returnsT

runGuarded

T

Same as run, except that synchronous errors are caught and forwarded via onError and not rethrown.

@paramfn(...args: any[]) => T
@paramapplyThisany
@paramapplyArgsany[] | undefined
@returnsT

runOutsideAngular

T

Executes the fn function synchronously in Angular's parent zone and returns value returned by the function.

Running functions via runOutsideAngular allows you to escape Angular's zone and do work that doesn't trigger Angular change-detection or is subject to Angular's error handling.

Any future tasks or microtasks scheduled from within this function will continue executing from outside of the Angular zone.

Use run to reenter the Angular zone and do work that updates the application model.

@paramfn(...args: any[]) => T
@returnsT

isInAngularZone

boolean

This method checks whether the method call happens within an Angular Zone instance.

@returnsboolean

assertInAngularZone

void

Assures that the method is called within the Angular Zone, otherwise throws an error.

@returnsvoid

assertNotInAngularZone

void

Assures that the method is called outside of the Angular Zone, otherwise throws an error.

@returnsvoid
Jump to details