EmbeddedViewRef

来源:互联网 发布:js 对象访问器 编辑:程序博客网 时间:2024/05/21 10:16

class EmbeddedViewRef extends ViewRef {
get context(): C
get rootNodes(): any[]
}

描述

Represents an Angular View.
代表一个angular视图
A View is a fundamental building block of the application UI. It is the smallest grouping of Elements which are created and destroyed together.
一个view是应用程序UI的基本构建块。它是可以一起创建和销毁的最小的元素组合。
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 ViewContainerRef. Each View can contain many View Containers.
一个视图中元素的属性可以更改,但View中的元素的结构(数量和顺序)不能。
更改Elements的结构只能通过ViewContainerRef插入,移动或删除嵌套视图来完成。
每个视图都可以包含许多视图容器。

例子

如有以下模板

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

我们有了两个 templateRef

外层templateRef
Count: {{items.length}}

<ul>  <ng-template ngFor let-item [ngForOf]="items"></ng-template></ul>

内层templateRef

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

请注意,原始模板分为两个单独的TemplateRefs。

然后将外部/内部TemplateRefs组合成如下所示的视图:

<!-- 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 -->