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
|
|
|
|
*/
|
|
|
|
|
2016-06-08 16:38:52 -07:00
|
|
|
import {ElementRef} from './element_ref';
|
2016-04-13 17:05:17 -07:00
|
|
|
import {EmbeddedViewRef} from './view_ref';
|
2015-07-17 08:03:40 -07:00
|
|
|
|
2016-11-01 11:12:25 -07:00
|
|
|
|
2015-07-17 08:03:40 -07:00
|
|
|
/**
|
2018-09-11 12:09:09 -07:00
|
|
|
* Represents an embedded template that can be used to instantiate embedded views.
|
|
|
|
* To instantiate embedded views based on a template, use {@link ViewContainerRef#
|
|
|
|
* createEmbeddedView}.
|
|
|
|
*
|
|
|
|
* Access a `TemplateRef` instance by placing a directive (or directive prefixed with `*`)
|
|
|
|
* on an `<ng-template>` element. The `TemplateRef` for the embedded view
|
|
|
|
* is injected into the constructor of the directive,
|
|
|
|
* using the `TemplateRef` token.
|
|
|
|
*
|
|
|
|
* You can also use a `Query` to find a `TemplateRef` associated with
|
|
|
|
* a component or a directive.
|
2015-07-17 08:03:40 -07:00
|
|
|
*
|
2018-09-11 12:09:09 -07:00
|
|
|
* @see `ViewContainerRef`
|
|
|
|
* @see [Navigate the Component Tree with DI](guide/dependency-injection-navtree)
|
2018-04-05 22:31:44 +01:00
|
|
|
*
|
2015-07-17 08:03:40 -07:00
|
|
|
*/
|
2016-04-28 14:00:31 -07:00
|
|
|
export abstract class TemplateRef<C> {
|
2015-07-17 08:03:40 -07:00
|
|
|
/**
|
2018-09-11 12:09:09 -07:00
|
|
|
* The anchor element in the parent view for this embedded view.
|
2015-09-21 12:32:25 -07:00
|
|
|
*
|
2018-09-11 12:09:09 -07:00
|
|
|
* The data-binding and injection contexts of embedded views created from this `TemplateRef`
|
2015-09-21 12:32:25 -07:00
|
|
|
* inherit from the contexts of this location.
|
|
|
|
*
|
2018-09-11 12:09:09 -07:00
|
|
|
* Typically new embedded views are attached to the view container of this location, but in
|
|
|
|
* advanced use-cases, the view can be attached to a different container while keeping the
|
2015-09-21 12:32:25 -07:00
|
|
|
* data-binding and injection context from the original location.
|
2015-09-18 15:46:26 -07:00
|
|
|
*
|
2015-07-17 08:03:40 -07:00
|
|
|
*/
|
2015-09-21 12:32:25 -07:00
|
|
|
// TODO(i): rename to anchor or location
|
2017-09-28 13:36:56 -07:00
|
|
|
abstract get elementRef(): ElementRef;
|
2016-04-13 17:05:17 -07:00
|
|
|
|
2018-09-11 12:09:09 -07:00
|
|
|
/**
|
|
|
|
* Creates a view object and attaches it to the view container of the parent view.
|
|
|
|
* @param context The context for the new view, inherited from the anchor element.
|
|
|
|
* @returns The new view object.
|
|
|
|
*/
|
2016-04-28 14:00:31 -07:00
|
|
|
abstract createEmbeddedView(context: C): EmbeddedViewRef<C>;
|
2015-10-06 06:53:39 -07:00
|
|
|
}
|