填写这份《一分钟调查》,帮我们(开发组)做得更好!去填写Home

EmbeddedViewRef

表示视图容器中的 Angular 视图嵌入视图可以从在模板中定义它的宿主组件之外的组件中引用,也可以由 TemplateRef 进行独立定义。

Represents an Angular view in a view container. An embedded view can be referenced from a component other than the hosting component whose template defines it, or it can be defined independently by a TemplateRef.

查看"说明"...

      
      abstract class EmbeddedViewRef<C> extends ViewRef {
  abstract context: C
  abstract rootNodes: any[]

  // 继承自 core/ViewRef
  abstract destroyed: boolean
  abstract destroy(): void
  abstract onDestroy(callback: Function): any

  // 继承自 core/ChangeDetectorRef
  abstract markForCheck(): void
  abstract detach(): void
  abstract detectChanges(): void
  abstract checkNoChanges(): void
  abstract reattach(): void
}
    

参见

说明

视图中元素的属性可以更改,但是视图中元素的结构(数量和顺序)不能更改。通过在视图容器中插入,移动或删除嵌套视图来更改元素的结构。

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.

Further information available in the Usage Notes...

属性

属性说明
abstract context: C

该视图的上下文,继承自锚点元素。

The context for this view, inherited from the anchor element.

abstract rootNodes: any[]只读

此嵌入式视图的根节点。

The root nodes for this embedded view.

使用说明

以下模板分为两个单独的 TemplateRef 实例,一个外部实例和一个内部实例。

The following template breaks down into two separate TemplateRef instances, an outer one and an inner one.

      
      Count: {{items.length}}
<ul>
  <li *ngFor="let  item of items">{{item}}</li>
</ul>
    

这是外部 TemplateRef

This is the outer TemplateRef:

      
      Count: {{items.length}}
<ul>
  <ng-template ngFor let-item [ngForOf]="items"></ng-template>
</ul>
    

这是内部的 TemplateRef

This is the inner TemplateRef:

      
      <li>{{item}}</li>
    

外部和内部 TemplateRef 实例按如下方式组装到视图中:

The outer and inner TemplateRef instances are assembled into views as follows:

      
      <!-- ViewRef: outer-0 -->
Count: 2
<ul>
  <ng-template view-container-ref></ng-template>
  <!-- ViewRef: inner-1 --><li>first</li><!-- /ViewRef: inner-1 -->
  <!-- ViewRef: inner-2 --><li>second</li><!-- /ViewRef: inner-2 -->
</ul>
<!-- /ViewRef: outer-0 -->