import {ChangeDetectorRef} from '../change_detection/change_detector_ref'; import {ChangeDetectionStrategy} from '../change_detection/constants'; import {unimplemented} from '../facade/exceptions'; import {AppView} from './view'; /** * @stable */ export abstract class ViewRef { get destroyed(): boolean { return unimplemented(); } abstract onDestroy(callback: Function): any /** TODO #9100 */; } /** * Represents an Angular View. * * * A View is a fundamental building block of the application UI. It is the smallest grouping of * Elements which are created and destroyed together. * * Properties of elements in a View can change, but the structure (number and order) of elements in * a View cannot. Changing the structure of Elements can only be done by inserting, moving or * removing nested Views via a {@link ViewContainerRef}. Each View can contain many View Containers. * * * ### Example * * Given this template... * * ``` * Count: {{items.length}} * * ``` * * We have two {@link TemplateRef}s: * * Outer {@link TemplateRef}: * ``` * Count: {{items.length}} * * ``` * * Inner {@link TemplateRef}: * ``` *
  • {{item}}
  • * ``` * * Notice that the original template is broken down into two separate {@link TemplateRef}s. * * The outer/inner {@link TemplateRef}s are then assembled into views like so: * * ``` * * Count: 2 * * * ``` * @experimental */ export abstract class EmbeddedViewRef extends ViewRef { get context(): C { return unimplemented(); } get rootNodes(): any[] { return unimplemented(); }; /** * Destroys the view and all of the data structures associated with it. */ abstract destroy(): any /** TODO #9100 */; } export class ViewRef_ implements EmbeddedViewRef, ChangeDetectorRef { /** @internal */ _originalMode: ChangeDetectionStrategy; constructor(private _view: AppView) { this._view = _view; this._originalMode = this._view.cdMode; } get internalView(): AppView { return this._view; } get rootNodes(): any[] { return this._view.flatRootNodes; } get context() { return this._view.context; } get destroyed(): boolean { return this._view.destroyed; } markForCheck(): void { this._view.markPathToRootAsCheckOnce(); } detach(): void { this._view.cdMode = ChangeDetectionStrategy.Detached; } detectChanges(): void { this._view.detectChanges(false); } checkNoChanges(): void { this._view.detectChanges(true); } reattach(): void { this._view.cdMode = this._originalMode; this.markForCheck(); } onDestroy(callback: Function) { this._view.disposables.push(callback); } destroy() { this._view.destroy(); } }