TemplateRef

TemplateRef

Stable Class

Class Overview

class TemplateRef {
  C 
  elementRef : ElementRef
  createEmbeddedView(context: C) : EmbeddedViewRef<C>
}

Class Description

Represents an Embedded Template that can be used to instantiate Embedded Views.

You can access a TemplateRef, in two ways. Via a directive placed on a <ng-template> element (or directive prefixed with *) and have the TemplateRef for this Embedded View injected into the constructor of the directive using the TemplateRef Token. Alternatively you can query for the TemplateRef from a Component or a Directive via Query.

To instantiate Embedded Views based on a Template, use ViewContainerRef, which will create the View and attach it to the View Container.

Class Details

C
elementRef : ElementRef

The location in the View where the Embedded View logically belongs to.

The data-binding and injection contexts of Embedded Views created from this TemplateRef inherit from the contexts of this location.

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 data-binding and injection context from the original location.

createEmbeddedView(context: C) : EmbeddedViewRef<C>

exported from core-index, defined in core/src/linker/template_ref.ts

© 2010–2017 Google, Inc.
Licensed under the Creative Commons Attribution License 4.0.
https://angular.io/docs/ts/latest/api/core/index/TemplateRef-class.html

在线笔记
App下载
App下载

扫描二维码

下载编程狮App

公众号
微信公众号

编程狮公众号

意见反馈
返回顶部