import { EventEmitter } from 'angular2/src/facade/async'; export { NgZoneError } from './ng_zone_impl'; /** * An injectable service for executing work inside or outside of the Angular zone. * * 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 {@link #runOutsideAngular} and if needed, these tasks * can reenter the Angular zone via {@link #run}. * * * * ### Example ([live demo](http://plnkr.co/edit/lY9m8HLy7z06vDoUaSN2?p=preview)) * ``` * import {Component, View, NgZone} from 'angular2/core'; * import {NgIf} from 'angular2/common'; * * @Component({ * selector: 'ng-zone-demo'. * template: ` *
Progress: {{progress}}%
*= 100">Done processing {{label}} of Angular zone!
* * * * `, * directives: [NgIf] * }) * export class NgZoneDemo { * progress: number = 0; * label: string; * * constructor(private _ngZone: NgZone) {} * * // Loop inside the Angular zone * // so the UI DOES refresh after each setTimeout cycle * processWithinAngularZone() { * this.label = 'inside'; * this.progress = 0; * this._increaseProgress(() => console.log('Inside Done!')); * } * * // Loop outside of the Angular zone * // so the UI DOES NOT refresh after each setTimeout cycle * processOutsideOfAngularZone() { * this.label = 'outside'; * this.progress = 0; * this._ngZone.runOutsideAngular(() => { * this._increaseProgress(() => { * // reenter the Angular zone and display done * this._ngZone.run(() => {console.log('Outside Done!') }); * }})); * } * * * _increaseProgress(doneCallback: () => void) { * this.progress += 1; * console.log(`Current progress: ${this.progress}%`); * * if (this.progress < 100) { * window.setTimeout(() => this._increaseProgress(doneCallback)), 10) * } else { * doneCallback(); * } * } * } * ``` */ export declare class NgZone { static isInAngularZone(): boolean; static assertInAngularZone(): void; static assertNotInAngularZone(): void; private _zoneImpl; private _hasPendingMicrotasks; private _hasPendingMacrotasks; /** * @param {bool} enableLongStackTrace whether to enable long stack trace. They should only be * enabled in development mode as they significantly impact perf. */ constructor({enableLongStackTrace}: { enableLongStackTrace?: boolean; }); private _checkStable(); /** * Notifies when code enters Angular Zone. This gets fired first on VM Turn. */ onUnstable: EventEmitter