ng-template 和 TemplateRef.createEmbeddedView

简介: ng-template 和 TemplateRef.createEmbeddedView

源代码:

image.png

image.pngimage.pngTemplateRef对应ng-template的引用。

看一个实际的例子:

template 文件里,定义一个id为tpl的ng-template:image.pngimage.png首先使用依赖注入,拿到ViewContainerRef引用。

使用@ViewChild, 拿到id为tpl的ng-template引用,类型为TemplateRef.

调用ViewContainerReference, 创建tpl模板实例。

注意,this.vcRef.createEmbeddedView, 虽然传入的是templateRef,但实际上正是调用templateRef的createEmbeddedView方法。



image.png

2021-4-20

Represents an embedded template that can be used to instantiate embedded views.

TemplateRef代表一个嵌入的模板,可以被用来实例化嵌入视图。image.png

相关文章
|
存储 编译器 C++
【C++模板】——template
【C++模板】——template
|
API 容器
ng中的ng-content ng-template ng-container
ng中的ng-content ng-template ng-container
106 0
angular29-ng-hide,ng-show
angular29-ng-hide,ng-show
80 0
angular29-ng-hide,ng-show
|
JavaScript 前端开发 测试技术
一文了解 ng-template, ng-content, ng-container, 和 *ngTemplateOutlet的区别
一文了解 ng-template, ng-content, ng-container, 和 *ngTemplateOutlet的区别
144 0
一文了解 ng-template, ng-content, ng-container, 和 *ngTemplateOutlet的区别
SAP Spartacus 里 ng-template和ng-container的嵌套使用
SAP Spartacus 里 ng-template和ng-container的嵌套使用
105 0
SAP Spartacus 里 ng-template和ng-container的嵌套使用
ɵɵtemplate和ng-template的对应关系
ɵɵtemplate和ng-template的对应关系
ɵɵtemplate和ng-template的对应关系
cannot bind to cxOutlet since it is not a known property of ng template
cannot bind to cxOutlet since it is not a known property of ng template
cannot bind to cxOutlet since it is not a known property of ng template
|
JSON 数据格式 索引
小程序template-plump
组件数据绑定 【加精】使用 this.data 可以获取内部数据和属性值,修改它们应使用 setData  与普通的 WXML 模版类似,可以使用数据绑定,这样就可以向子组件的属性传递动态数据
1363 0
|
关系型数据库 MySQL 应用服务中间件