[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" ...
随机推荐
- Python单例模式研究
方法一 import threading class Singleton(object): __instance = None __lock = threading.Lock() # used t ...
- bzoj 3781 小B的询问(莫队算法)
[题意] 若干个询问sigma{ cnt[i]^2 } cnt[i]表示i在[l,r]内的出现次数. [思路] 莫队算法,裸题. 一个cnt数组即可维护插入与删除. [代码] #include< ...
- Eclipse安装插件的方式
Eclipse有两种安装插件的方式,分为在线安装和手动安装,因为受到网络环境限制,推荐采用手动安装的方式,下面我们先来了解一下Eclipse手动安装插件的步骤. Eclipse手动安装插件: 第一种: ...
- Hadoop2的简单安装
前面花了很多时间来介绍hadoop1的安装,随着hadoop的发展,hadoop2的应用也越来越普及,hadoop2解决了hadoop1中的很多问题,比如单点故障,namenode容量小的问题. 我们 ...
- mysql cluster 名词概念解读
Node Group [number_of_node_groups] = number_of_data_nodes / NoOfReplicas Partition When using ndbd, ...
- 【MySQL】源码编译安装和配置MySql 5.5.32(单实例)
[需求描述] 在CentOS环境中,通过编译源码的方式,安装并且配置“单实例”的MySQL5.5.32数据库. MySQL的安装目录为:/application/mysql-5.5.32 MySQL数 ...
- 异步编程之Promise(2):探究原理
异步编程系列教程: (翻译)异步编程之Promise(1)--初见魅力 异步编程之Promise(2):探究原理 异步编程之Promise(3):拓展进阶 异步编程之Generator(1)--领略魅 ...
- MYSQL数据库性能调优之三:explain分析慢查询
explain显示了mysql如何使用索引来处理select语句以及连接表.可以帮助选择更好的索引和写出更优化的查询语句.使用方法,在select语句前加上explain就可以了. 一.explain ...
- C语言中返回字符串函数的四种实现方法 2015-05-17 15:00 23人阅读 评论(0) 收藏
C语言中返回字符串函数的四种实现方法 分类: UNIX/LINUX C/C++ 2010-12-29 02:54 11954人阅读 评论(1) 收藏 举报 语言func存储 有四种方式: 1.使用堆空 ...
- Controlling GameObjects Using Components
[Accessing Components] The most common case is where a script needs access to other Components attac ...