Angular 2 templates have a special let syntax that allows you to define and pass a context when they’re being generated.

We have template:

<template #template let-description="description">
<h2>My {{description}} template</h2>
<button>My {{description}} button</button>
</template>

And we define 'description' variable to let data to pass into.

import {Component, ViewChild, ViewContainerRef, ComponentFactoryResolver} from "@angular/core";
import {WidgetThree} from "../widgets/widget-three.component";
@Component({
selector: 'home',
template: `
<button (click)="onClick()">Create Template</button>
<div #container></div> <template #template let-description="description">
<h2>My {{description}} template</h2>
<button>My {{description}} button</button>
</template>
`
})
export class HomeComponent{
@ViewChild('container', {read:ViewContainerRef}) container;
@ViewChild('template') template; constructor(){} onClick(){
this.container.createEmbeddedView(this.template, {
description: 'sweet'
});
}
}

[Angular 2] Set Values on Generated Angular 2 Templates with Template Context的更多相关文章

  1. Computer Generated Angular Fisheye Projections [转]

    Computer GeneratedAngular Fisheye Projections Written by Paul Bourke May 2001 There are two main ide ...

  2. [Angular 2 Router] Configure Your First Angular 2 Route

    Using the Angular 2 router requires defining routes, passing them in to the RouterModule.forRoot and ...

  3. 【Angular专题】——(1)Angular,孤傲的变革者

    目录 一. 漫谈Angular 二. 如果你还在使用Angularjs 三. 我计划这样学习Angular技术栈 一. 漫谈Angular Angular,来自Google的前端SPA框架,与Reac ...

  4. [Angular] Use Angular components in AngularJS applications with Angular Elements

    When migrating AngularJS (v1.x) applications to Angular you have different options. Using Angular El ...

  5. [Angular] Bind async requests in your Angular template with the async pipe and the "as" keyword

    Angular allows us to conveniently use the async pipe to automatically register to RxJS observables a ...

  6. Angular 从入坑到挖坑 - Angular 使用入门

    一.Overview angular 入坑记录的笔记第一篇,完成开发环境的搭建,以及如何通过 angular cli 来创建第一个 angular 应用.入坑一个多星期,通过学习官方文档以及手摸手的按 ...

  7. [从 0 开始的 Angular 生活]No.38 实现一个 Angular Router 切换组件页面(一)

    前言 今天是进入公司的第三天,为了能尽快投入项目与成为团队可用的战力,我正在努力啃官方文档学习 Angular 的知识,所以这一篇文章主要是记录我如何阅读官方文档后,实现这个非常基本的.带导航的网页应 ...

  8. Angular项目构建指南 - 不再为angular构建而犹豫不决(转)

    如果你不知道什么是Angular或者根本没听说过,那么我接下来所说的对你来说毫无益处,不过如果你打算以后会接触Angular或者干脆要涨涨姿势~读下去还是有点用的. Angular和它之前所出现的其余 ...

  9. [Angular 2] A Simple Form in Angular 2

    When you create a Form in Angular 2, you can easily get all the values from the Form using ControlGr ...

随机推荐

  1. ActiveMQ学习总结(2)——ActiveMQ入门实例教程

    1.下载ActiveMQ 去官方网站下载:http://activemq.apache.org/ 2.运行ActiveMQ 解压缩apache-activemq-5.5.1-bin.zip,然后双击a ...

  2. LightOJ 1063 Ant Hills

    Ant Hills Time Limit: 2000ms Memory Limit: 32768KB This problem will be judged on LightOJ. Original ...

  3. 火狐—火狐浏览器中的“HttpWatch”

    在IE下通过HttpWatch能够查看HTTP请求的相关细节.这对我们分析程序的运行效率很有帮助,但是在火狐浏览器中的难道就没有相似的工具了吗?答案是否定的--火狐浏览器中也有.在火狐浏览器中该工具叫 ...

  4. Python - 字典按值(value)排序

    字典安值排序是一个伪命题. 字典本身是不能被排序的, 已经依照关键字(key)排序, 可是列表(list)和元组(tuple)能够排序, 所以字典须要转换列表后排序. 如 import operato ...

  5. js40---享元模式

    /** * 享元模式是一个为了提高性能(空间复杂度)的设计模式 * 他使用与程序会生产大量的相类似的对象是耗用大量的内存的问题 */ (function(){ /** * 制造商 * 型号 * 拥有者 ...

  6. gulp几个常见问题及解决方案

    1. 找不到local gulp 报错代码: $ gulp [23:29:31] Local gulp not found in [23:29:31] Try running: npm install ...

  7. JS正则 replace()方法全局替换变量(可以对变量进行全文替换)

    转至:https://www.cnblogs.com/jasonlam/p/7070604.html var text = "饿~,23333.饿~,测试yongde"; var ...

  8. C#中选中指定文件并读取类似ini文件的内容

    一.背景 由于项目中需要去读取设备的配置信息,配置文件的内容和INI配置文件的格式类似,所以可以按照INI文件的方式来处理.涉及如何打开一个文件,获取打开的文件的路径问题,并读取选中的文件里边的内容. ...

  9. 【Codeforces Round #452 (Div. 2) D】Shovel Sale

    [链接] 我是链接,点我呀:) [题意] 在这里输入题意 [题解] 让N乘2->a 然后看一下位数是多少. 假设有x位(x>=2) 则(0..(a%10-1) ) + (99..9)[x- ...

  10. Shiro学习总结(10)——Spring集成Shiro

    1.引入Shiro的Maven依赖 [html] view plain copy <!-- Spring 整合Shiro需要的依赖 --> <dependency> <g ...