2016-06-23 09:47:54 -07:00
|
|
|
/**
|
|
|
|
* @license
|
|
|
|
* Copyright Google Inc. All Rights Reserved.
|
|
|
|
*
|
|
|
|
* Use of this source code is governed by an MIT-style license that can be
|
|
|
|
* found in the LICENSE file at https://angular.io/license
|
|
|
|
*/
|
|
|
|
|
2017-02-17 08:56:49 -08:00
|
|
|
import {ApplicationRef} from '../application_ref';
|
2015-08-06 13:19:29 -07:00
|
|
|
import {ChangeDetectorRef} from '../change_detection/change_detector_ref';
|
2016-06-08 16:38:52 -07:00
|
|
|
|
2018-08-20 14:32:11 -07:00
|
|
|
/**
|
|
|
|
* Represents an Angular [view](guide/glossary#view),
|
|
|
|
* specifically the [host view](guide/glossary#view-tree) that is defined by a component.
|
|
|
|
* Also serves as the base class
|
|
|
|
* that adds destroy methods for [embedded views](guide/glossary#view-tree).
|
|
|
|
*
|
|
|
|
* @see `EmbeddedViewRef`
|
|
|
|
*/
|
2016-11-04 14:40:37 -07:00
|
|
|
export abstract class ViewRef extends ChangeDetectorRef {
|
2016-11-24 11:32:28 +01:00
|
|
|
/**
|
2018-08-20 14:32:11 -07:00
|
|
|
* Destroys this view and all of the data structures associated with it.
|
2016-11-24 11:32:28 +01:00
|
|
|
*/
|
|
|
|
abstract destroy(): void;
|
|
|
|
|
2018-08-20 14:32:11 -07:00
|
|
|
/**
|
|
|
|
* Reports whether this view has been destroyed.
|
|
|
|
* @returns True after the `destroy()` method has been called, false otherwise.
|
|
|
|
*/
|
2017-09-28 13:36:56 -07:00
|
|
|
abstract get destroyed(): boolean;
|
2015-04-28 11:20:01 -07:00
|
|
|
|
2018-08-20 14:32:11 -07:00
|
|
|
/**
|
|
|
|
* A lifecycle hook that provides additional developer-defined cleanup
|
|
|
|
* functionality for views.
|
|
|
|
* @param callback A handler function that cleans up developer-defined data
|
|
|
|
* associated with a view. Called when the `destroy()` method is invoked.
|
|
|
|
*/
|
2016-06-08 15:45:15 -07:00
|
|
|
abstract onDestroy(callback: Function): any /** TODO #9100 */;
|
2015-09-18 15:46:26 -07:00
|
|
|
}
|
2015-07-11 17:26:48 +02:00
|
|
|
|
2015-04-28 11:20:01 -07:00
|
|
|
/**
|
2018-08-20 14:32:11 -07:00
|
|
|
* Represents an Angular [view](guide/glossary#view) in a view container.
|
|
|
|
* An [embedded view](guide/glossary#view-tree) can be referenced from a component
|
|
|
|
* other than the hosting component whose template defines it, or it can be defined
|
|
|
|
* independently by a `TemplateRef`.
|
2015-07-07 08:15:58 +02:00
|
|
|
*
|
2018-08-20 14:32:11 -07:00
|
|
|
* Properties of elements in a view can change, but the structure (number and order) of elements in
|
|
|
|
* a view cannot. Change the structure of elements by inserting, moving, or
|
|
|
|
* removing nested views in a view container.
|
2015-07-07 08:15:58 +02:00
|
|
|
*
|
2018-08-20 14:32:11 -07:00
|
|
|
* @see `ViewContainerRef`
|
2015-07-07 08:15:58 +02:00
|
|
|
*
|
2018-09-11 12:09:09 -07:00
|
|
|
* @usageNotes
|
|
|
|
*
|
2018-08-20 14:32:11 -07:00
|
|
|
* The following template breaks down into two separate `TemplateRef` instances,
|
|
|
|
* an outer one and and an inner one.
|
2015-07-07 08:15:58 +02:00
|
|
|
*
|
|
|
|
* ```
|
|
|
|
* Count: {{items.length}}
|
|
|
|
* <ul>
|
2016-04-25 19:52:24 -07:00
|
|
|
* <li *ngFor="let item of items">{{item}}</li>
|
2015-07-07 08:15:58 +02:00
|
|
|
* </ul>
|
|
|
|
* ```
|
|
|
|
*
|
2018-08-20 14:32:11 -07:00
|
|
|
* This is the outer `TemplateRef`:
|
2015-07-07 08:15:58 +02:00
|
|
|
*
|
|
|
|
* ```
|
|
|
|
* Count: {{items.length}}
|
|
|
|
* <ul>
|
2017-01-09 13:16:46 -08:00
|
|
|
* <ng-template ngFor let-item [ngForOf]="items"></ng-template>
|
2015-07-07 08:15:58 +02:00
|
|
|
* </ul>
|
|
|
|
* ```
|
|
|
|
*
|
2018-08-20 14:32:11 -07:00
|
|
|
* This is the inner `TemplateRef`:
|
2018-05-18 16:13:00 +01:00
|
|
|
*
|
2015-07-07 08:15:58 +02:00
|
|
|
* ```
|
|
|
|
* <li>{{item}}</li>
|
|
|
|
* ```
|
|
|
|
*
|
2018-08-20 14:32:11 -07:00
|
|
|
* The outer and inner `TemplateRef` instances are assembled into views as follows:
|
2015-07-07 08:15:58 +02:00
|
|
|
*
|
|
|
|
* ```
|
2015-07-11 17:26:48 +02:00
|
|
|
* <!-- ViewRef: outer-0 -->
|
2015-07-07 08:15:58 +02:00
|
|
|
* Count: 2
|
|
|
|
* <ul>
|
2017-01-09 13:16:46 -08:00
|
|
|
* <ng-template view-container-ref></ng-template>
|
2015-07-07 08:15:58 +02:00
|
|
|
* <!-- ViewRef: inner-1 --><li>first</li><!-- /ViewRef: inner-1 -->
|
|
|
|
* <!-- ViewRef: inner-2 --><li>second</li><!-- /ViewRef: inner-2 -->
|
|
|
|
* </ul>
|
2015-07-11 17:26:48 +02:00
|
|
|
* <!-- /ViewRef: outer-0 -->
|
2015-07-07 08:15:58 +02:00
|
|
|
* ```
|
2016-05-25 15:00:05 -07:00
|
|
|
* @experimental
|
2015-04-28 11:20:01 -07:00
|
|
|
*/
|
2016-04-28 14:00:31 -07:00
|
|
|
export abstract class EmbeddedViewRef<C> extends ViewRef {
|
2018-09-11 12:09:09 -07:00
|
|
|
/**
|
|
|
|
* The context for this view, inherited from the anchor element.
|
|
|
|
*/
|
2017-09-28 13:36:56 -07:00
|
|
|
abstract get context(): C;
|
2015-04-28 11:20:01 -07:00
|
|
|
|
2018-09-11 12:09:09 -07:00
|
|
|
/**
|
|
|
|
* The root nodes for this embedded view.
|
|
|
|
*/
|
2017-09-28 13:36:56 -07:00
|
|
|
abstract get rootNodes(): any[];
|
2015-12-02 10:35:51 -08:00
|
|
|
}
|
|
|
|
|
2017-02-17 08:56:49 -08:00
|
|
|
export interface InternalViewRef extends ViewRef {
|
2017-02-22 10:05:56 -08:00
|
|
|
detachFromAppRef(): void;
|
2017-02-17 08:56:49 -08:00
|
|
|
attachToAppRef(appRef: ApplicationRef): void;
|
|
|
|
}
|