[Angular] Learn How To Use ng-template Inputs
For example, we have a modal component, it can config that using ng-template as a configurable template.
<ng-template #auModalBody></ng-template> <au-modal [body]="auModalBody" ></au-modal>
Now what we want to do is to pass in inputs to ng-templates so that template can change dynamiclly according to the inputs.
For example:
<ng-template #auModalBody
let-title="title" <!-- define a title prop -->
let-tabActivated=loginTabActivated <!-- define a tabActivated prop -->
>
<!-- we can use 'title' & 'tabActivated' props here -->
<h2>{{title}}</h2>
<tab [selected]="tabActivated" #login />
<tab [selected]="!tabActivated" #signUp />
</ng-template> <au-modal [body]="auModalBody" [context]="{
title: 'Login or Sign up',
tabActivated: loginTabActivated <!-- based on those variables we passed in-->
}"></au-modal>
To do that, we need to add an @Input to au-modal component:
@Input() context: any;
<ng-container *ngIf="body; else projectionBody">
<ng-container *ngTemplateOutlet="body; context:context" ></ng-container>
</ng-container>
See the commit: Github
[Angular] Learn How To Use ng-template Inputs的更多相关文章
- [Angular] Create a custom validator for template driven forms in Angular
User input validation is a core part of creating proper HTML forms. Form validators not only help yo ...
- Follow me to learn how to use mvc template
Introduction After having gone through many project: Project A Project B Project C I start to write ...
- Angular 中后台前端解决方案 - Ng Alain 介绍
背景 之前项目使用过vue.js+iview,习惯了后端开发的我,总觉得使用不习惯,之前分析易企秀前端代码,接触到了angular js,完备的相关功能,类似后端开发的体验,让人耳目一新,全新的ang ...
- [Angular] Using ngTemplateOutlet to create dynamic template
I can use <tamplete> syntax and a entry component as a container to create a dynamic component ...
- [Angular 2] Using ng-for to repeat template elements
This lesson covers Angular 2’s version of looping through data in your templates: ng-for. It’s conce ...
- angular.min.js:118 Error: [ng:areq] http://errors.angularjs.org/1.5.8/ng/areq?
1,错误如图所示 简单说下错误原因是:没有js没有注册进去. 解决方法: 1.看下index.html有没有引入你的js文件. 2.看下app.js有没有注册js,比如我这次就是这步没做好,合并代码时 ...
- AngularJS中angular.min.js:80 Error: [ng:areq] http://errors.angularjs.org/1.2.9/ng/areq
报出来的时候,出现这种错误,是因为在引入控制器的时候没有引入成功,我遇到这个错误是在因为没有将父控制器引入到子控制器中.
- [Angular] Learn Angular Multi-Slot Content Projection
Now for au-modal component, we pass in tow component though contenct projection: <au-modal class= ...
- Angular: 执行ng lint后如何快速修改错误
当我第一次被分配到“修正执行ng lint语句后的错误”这项任务前,我就被导师提前告知这是一个很无聊的任务,当我开始后,我发现其实有一些办法可以加快这个无聊单调的工作.接下来,我就分享一下我的经验. ...
随机推荐
- BZOJ 1571 DP
思路: 预处理出在能力值为i的时候 滑雪一次的最小时间 f[i][j]表示i时间 j的能力值 最多的滑雪次数 我先用vector 把课程按起点push进去 1. for(int k=0;k<ve ...
- 基于Linux平台的Openvas配置使用视频教学
常见的漏洞扫描工具有Openvas.LSAT.Nessus.X-scan.ShadowSecurityScanner和流光等,openvas是一款最全面的开源漏洞扫描工具,由于openvas安装比较困 ...
- linux 下find---xargs以及find--- -exec结合使用
例:删除/home/raven下,包括子目录里所有名为abc.txt的文件: find /home/raven -name abc.txt | xargs rm -rf 如果不使用xargs,则为: ...
- 【hdu 4289】Control
[Link]:http://acm.hdu.edu.cn/showproblem.php?pid=4289 [Description] 给出一个又n个点,m条边组成的无向图.给出两个点s,t.对于图中 ...
- 推断字符串string是数字、json结构、xml结构
import org.json.JSONException; import org.json.JSONObject; import org.dom4j.DocumentException; impor ...
- Python之字符串切片
切片操作(slice)可以从一个字符串中获取子字符串(字符串的一部分).我们使用一对方括号.起始偏移量start.终止偏移量end 以及可选的步长step 来定义一个分片. 格式: [start:en ...
- 03002_MySQL数据库的安装和配置
1.MySQL的安装 (1)下载mysql-5.5.49-win32.msi, 链接:MySQL安装包下载 密码:geqh : (2)打开下载的MySQL安装文件mysql-5.5.27-win32. ...
- Kurento应用开发指南(以Kurento 5.0为模板) 之中的一个:简单介绍,安装与卸载
文件夹 1. Kurento是什么 3 2. Kurento简单介绍 3 2.1 WebRTC媒体server ...
- 使用IPV6
使用IPV6 知道IPV6已经很久了,但是一直没有使用过. 我使用的IPV4网络一般是 内网-->外网-->互联网,IPV6也不外乎这样,但是对IPV6而言,必须有它的"世界&q ...
- 非极大值抑制(non-maximum suppression)的理解与实现
非极大抑制(Non-Maximum Suppression) Non-Maximum Suppression for Object Detection in Python RCNN 和微软提出的 SP ...