[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语句后的错误”这项任务前,我就被导师提前告知这是一个很无聊的任务,当我开始后,我发现其实有一些办法可以加快这个无聊单调的工作.接下来,我就分享一下我的经验. ...
随机推荐
- 三个角度解构云计算,商业驱动or技术驱动?
从云计算的使用者到云服务的输出者,大多互联网公司在过去一年完成了角色的转换,也让云计算的未来更加扑朔迷离.不过,抛却进入时间这个评判因素,单从技术和商业化的角度来解构云计算的话,对于云计算的格局以及未 ...
- Cisco PIX防火墙PPPoE拨号配置视频教学
Cisco PIX防火墙PPPoE拨号配置视频教学 本文出自 "李晨光原创技术博客" 博客,请务必保留此出处http://chenguang.blog.51cto.com/35 ...
- javafx virtual keyboard
public class EffectTest extends Application { @Override public void start(final Stage stage) { final ...
- JSP_Learn
// 解决中文乱码的问题String name = new String((request.getParameter("name")).getBytes("ISO-885 ...
- 负载均衡之lvs
集群(cluster):将一组计算机软/硬件连接起来,高度紧密的协作完成计算工作,其中的单个计算机通常称为节点.负载均衡集群(Load Balancing):通过负载均衡器,将负载尽可能平均分摊处理. ...
- 洛谷 P3505 [POI2010]TEL-Teleportation
P3505 [POI2010]TEL-Teleportation 题目描述 King Byteasar is the ruler of the whole solar system that cont ...
- CCNP路由实验之十五 NAT(网络地址转换)
CCNP路由实验之十五 NAT(网络地址转换) 众所周知,要让自己的电脑连上Internet,必须要到运营商(ISP)申请一个上网账号,依据此账号申请自己的宽频业务(拨号上网.商业固定IP等等) ...
- Cocos2d-x 之大牛看法
(未完毕) cocos2d-x并非一个适合网游client(mmo)的游戏引擎.越是大型游戏,这个小引擎就越无法驾驭(尽管它很受欢迎). 之前我在原来的公司使用的是自主研发的C3引擎,已经对外开放(尚 ...
- 码农的救赎:使用Github Pages搭建博客
人生若仅仅如初见,都恨太晚 据说有博客的人比没博客人的薪水要高非常多,相传写博客也是一个高手的标配,尽管之前一直有在写(在这里).可是孤既不是高手.薪水还比别人少.之前一直在CSDN上面写博客,那是一 ...
- js--27门面模式
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01//EN" "http://www.w3.org/TR/html4/stri ...