The most common use of this service is to optimize performance when starting a work consisting of one or more asynchronous tasks that don't require UI updates or error handling to be handled by Angular. Such tasks can be kicked off via runOutsideAngular and if needed, these tasks can reenter the Angular zone via run.
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.
Executes the fn function synchronously within the Angular zone and returns value returned by the function.
run<T>(fn: (...args: any[]) => T, applyThis?: any, applyArgs?: any[]): T
参数
fn
Type: (...args: any[]) => T.
applyThis
Type: any.
可选. 默认值是 undefined.
applyArgs
Type: any[].
可选. 默认值是 undefined.
返回值
T
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.
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.
Executes the fn function synchronously in Angular's parent zone and returns value returned by the function.
runOutsideAngular<T>(fn: (...args: any[]) => T): T
参数
fn
Type: (...args: any[]) => T.
返回值
T
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.