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. mysql 编码错误修改

    set character_set_results=utf8;

  2. 今日SGU 5.7

    SGU 169 题意:求k位数里面有多少个是完美数,完美数的定义就是n是好数,n+1也是好数,那么n就是完美数,好数就是n%p(n)==0&&p(n)!=0,p(n)=a1*...*a ...

  3. 【2017 Multi-University Training Contest - Team 2】 Regular polygon

    [Link]: [Description] 给你n个点整数点; 问你这n个点,能够组成多少个正多边形 [Solution] 整点只能构成正四边形. 则先把所有的边预处理出来; 枚举每某两条边为对角线的 ...

  4. notification-应用实例

    这几天接触到了notification,现在就把它的常用方法总结下. 直接看如下代码就行了 ComponentName componetName = new ComponentName("c ...

  5. c#的中英文混合字符串截取指定长度,startidx从0开始

    //c#的中英文混合字符串截取指定长度,startidx从0开始 by gisoracle@126.com public string getStrLenB(string str, int start ...

  6. servlet、filter、listener继承的基类和获得作用域的方式

    一.servlet: 1.servlet属于j2ee的组件,构建servlet的web project不需要导入项目框架jar包 2.servlet的体系结构:  在j2ee API中,提供给serv ...

  7. Debian9 安装后的配置笔记

    安装Debian9后,需要做的事,具体如下: 以下内容主要参考:https://www.cnblogs.com/OneFri/p/8308340.html感谢作者的分享. su 输入密码,登录root ...

  8. java 之 wait, notify, park, unpark , synchronized, Condition

    1. wait notify /** * 解释: 唤醒一个等待monitor的线程, 如果有多个线程在等待,会唤醒一个. * 一个线程在等待monitor是由Object.wait引起的 * 获取一个 ...

  9. gogodroid--android 上的IPV6工具

    gogodroid--android 上的IPV6工具 系统需求是 Android 1.6以上的系统,已经root,能够执行modprobe命令(在终端里输入modprobe,如果显示了帮助便可以), ...

  10. Nginx详细编译参数

    本参数基于Nginx-1.15.2安装包 一 路径参数 1.1.1 指定Nginx安装路径 --prefix=/usr/local/nginx- 1.1.2 设置Nginx可执行文件路径默认路径在 - ...