微信公众号搜"智元新知"关注
微信扫一扫可直接关注哦!

EmbeddedViewRef

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

版权声明:本文内容由互联网用户自发贡献,该文观点与技术仅代表作者本人。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌侵权/违法违规的内容, 请发送邮件至 dio@foxmail.com 举报,一经查实,本站将立刻删除。

相关推荐