[Angular 2] Create template with Params
Angular 2 templates have a special let syntax that allows you to define and pass a context when they’re being generated.
import {Component, ViewChild, ViewContainerRef, ComponentFactoryResolver, ViewChild} from '@angular/core';
import {SimpleService} from "../../serivces/simple.service";
import {WidgetThree} from "../widgets/widget-three.component";
@Component({
moduleId: module.id,
selector: 'home',
templateUrl: 'home.component.html'
})
export class HomeComponent {
@ViewChild('container', {
read: ViewContainerRef
}) container;
@ViewChild('template') template;
constructor(private resolver: ComponentFactoryResolver, private simpleService: SimpleService) {
}
ngAfterContentInit(){
const WidgetFactory = this.resolver.resolveComponentFactory(WidgetThree);
this.container.createComponent(WidgetFactory);
this.container.createComponent(WidgetFactory);
this.container.createComponent(WidgetFactory);
this.container.createComponent(WidgetFactory);
this.container.createComponent(WidgetFactory);
}
onClick(){
this.container.createEmbeddedView(
this.template,
{
desc: 'Good'
}
)
}
}
We pass in an Object "desc: Good", to the template, in tempalte, we use "let-" keyword to define the variable which we can reference to, and the object will be the 'context' for the template.
<template #template let-desc="desc">
<h3>tempalte {{desc}}</h3>
<section>tempalte {{desc}}</section>
<footer>template {{desc}}</footer>
</template>
[Angular 2] Create template with Params的更多相关文章
- R12: How to add Microsoft Excel as Type to the Create Template List of Values in BI Publisher (Doc ID 1343225.1)
Modified: 27-Oct-2013 Type: HOWTO In this Document Goal Solution References APPLIES TO: BI Publisher ...
- [Angular Directive] Create a Template Storage Service in Angular 2
You need to define a <template> to be able to use it elsewhere in your app as a TemplateRef. Y ...
- [Angular 2] Create Shareable Angular 2 Components
Components that you use across multiple applications need to follow a module pattern that keeps them ...
- [Angular 2] Create Angular 2 Porject with Angular CLI
Install: npm i -g angular-cli Create a project: ng new hello-angular2 Run the project: cd hello-angu ...
- [Angular 2] Create a simple search Pipe
This lesson shows you how to create a component and pass its properties as it updates into a Pipe to ...
- [Angular 2] Passing Template Input Values to Reducers
Angular 2 allows you to pass values from inputs simply by referencing them in the template and passi ...
- [Angular 2] Share Template Content In Another Template With Content Projection <ng-content>
Angular 1 provided a mechanism to place content from your template inside of another template called ...
- [Angular] Test component template
Component: import { Component, Input, ChangeDetectionStrategy, EventEmitter, Output } from '@angular ...
- 对angular实现延迟加载template和controller
1.在lib目录中添加 script.js 文件,并在index.html其他<script>之前引用之: <script src="lib/script.js" ...
随机推荐
- linux库文件编写入门(笔记)
linux库文件的编写 作者: laomai地址: http://blog.csdn.net/laomai 本文主要参考了如下资料⑴hcj写的"Linux静态/动态链接库的创建和使用&quo ...
- ACM2050前传
n在一个平面上有一个圆和n条直线,这些直线中每一条在圆内 同其他直线相交,假设没有3条直线相交于一点,试问这些直线 将圆分成多少区域. 使用递归 F(1)=2; F(n) = F(n-1)+n; ...
- 【脚本语言对比】BASH,PERL以及PYTHON
据说: BASH能调用linux的应用程序,这是其最大的优点,也是其最大的缺点. PERL那复杂的语法确实看得让人想吐. python很优美,但是据说对正则的支持不够,没有perl强大. 总结一下学习 ...
- c++中获取字符cin,getchar,get,getline的区别
http://www.imeee.cn/News/GouWu/20090801/221298.html cin.get()与getchar()函数有什么区别? 详细点..C++中几个输入函数的用法和区 ...
- cordova,phonegap 重力感应
3.0版本后,cordova通过插件模式实现设备API,使用CLI的plugin命令可以添加或者移除插件: $ cordova plugin add org.apache.cordova.device ...
- Hadoop Java开发实用快捷键收藏
不断总结更新.... Alt + / 补全 Ctrl + T 打出结构 Ctrl + 2 ,再选择 Quick Assist - Assign to local variable Ctrl ...
- HTML结构标签介绍
HTML:超文本标记语言 介绍HTML基本标记 1:头部标记(head)----- 头部的内容不会再页面上显示 在头部元素中,一般需要包括标题<title>,基本信息(文档样式, ...
- hdu 1155 Bungee Jumping
http://acm.hdu.edu.cn/showproblem.php?pid=1155 Bungee Jumping Time Limit: 2000/1000 MS (Java/Others) ...
- VPN 隧道协议PPTP、L2TP、IPSec和SSLVPN的区别
最近软矿频繁地介绍了各种VPN,有免费的PacketiX.NET和Hotspot Shield,有付费的Astrill VPN,iVPN和PureVPN.在介绍这些VPN的时候,常常会说到PPTP.L ...
- Python类的探讨
我们下面的探讨基于Python3,我实际测试使用的是Python3.2,Python3与Python2在类函数的类型上做了改变 1,类定义语法 Python类定义以关键字class开头,一个类定义例 ...