angular2 - content projection-
angular2中的内容映射:
App.component:
<my-day>
<my-lucky> </my-lucky>
</my-day>
MyDay.component:
selector:'my-day'
template`<h1>my day </h1>
<ng-content></ng-content>
`
MyLucky.component:
selector:'my-lucky',
template:'<p>One fine day</p> '
MyLucky中的内容就会映射到MyDayComponent的'ng-content'标签内;
@ContentChildren(MyLuckyComponent):;MYDay通过它访问;
------------------------------------------
ng-content
ng-content拥有一个select属性,允许选择性地加载组件。但必须保证,所供选择的组件都放在<my-day></my-day>内部。
:
<ng-content select='[one]'></ng-content> //按属性选择 ;;可以提供属性值:select='[one=*]',按属性值来加载。
选择:<my-lucky one> </my-lucky> 选择具有one属性的;
<ng-content select='my-lucky'></ng-content>//按标签选择
选择:<my-lucky></my-lucky>
<ng-content select='.class1'></ng-content>//按CSS选择;
选择:<div class='class1'></div>
在设置了select属性后,可允许一个组件内拥有多个ng-content,各自按须加载。
------------------------------------------------------
可惜ng-content select无法进行动态加载。
<ng-content select='{{selected}}'> 不行。
<my-lucky [one]='visibility.lucky'> 不行。
<my-lucky one='{{visibility.lucky}}'>不行。
好吧,我是这样的:
<my-day>
<my-lucky *ngIf='visibility.lucky'></my-lucky>
<my-wonderfull *ngIf='visibility.wonderfull'></my-wonderfull>
</my-day> <ng-content> </ng-content> //不写任何属性。
refer:https://scotch.io/tutorials/angular-2-transclusion-using-ng-content
我的Github例子:https://github.com/zhantewei2/Ionic2-example-notes/tree/master/pages/testSegment
angular2 - content projection-的更多相关文章
- [Angular] Learn Angular Multi-Slot Content Projection
Now for au-modal component, we pass in tow component though contenct projection: <au-modal class= ...
- [Angular] Configurable Angular Components - Content Projection and Input Templates
We are going to have a modal component: <au-modal > </au-modal> And we can pass default ...
- [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] Content Projection with ng-content
For example there is tow form compoennts on the page, and what we want to do is reusing the form com ...
- Angular2.0的项目架构
Angular2.0的项目架构 一.项目服务端app a) Controller控制器 b) Router路由 c) Service服务 d) Public公共样式及脚本和图片等静态资源 e) Vie ...
- C#版的mongodb最新的官方驱动2.4.0版本
已经升级了mongodb至最新的3.4的版本,我想想也该把驱动升到最新的了,我用的驱动还是1.7的版本呢,之前几次想升级,都是因为升级驱动需要改动的代码太大了,升级的成本很高,所以懒得动,就这么的用了 ...
- Angular:利用内容投射向组件输入ngForOf模板
现在,我们写一个组件puppiesListCmp,用于显示小狗狗的列表: //puppies-list.component.ts @Component({ selector: 'puppies-lis ...
- angular5 @viewChild @ContentChild ElementRef renderer2
@viewChild 作用一:选择组件内节点 <!--视图 --> <div #mydiv><input></div> // 选择 @ViewChild ...
- Angular4学习笔记(八)- ng-content
内容投影 ng-content ng-content是一个占位符,有些类似于router-outlet. 以前举の例子,父组件包含子组件都是直接指明子组件的selector,比如子组件的selecto ...
随机推荐
- node模块系统常用命令
node模块系统常用命令 命令 示例 备注 安装模块 npm install commander 最新版本 npm install commander@1.0.0 指定版本 npm install c ...
- #HTML:無序、有序與定義清單
#HTML:無序.有序與定義清單 Maplewing 于 星期六, 12/10/2013 - 09:48 提交 清單在網頁中是很常使用到的東西,故多少還是要了解一下.在HTML中有三種不太一樣的清單, ...
- 八皇后java算法
import java.util.Date; public class EightQueen { public static void main(String[] args) { long star ...
- 学习Find函数和select
Find函数其实就类似于在excel按下Ctrl+F出现的查找功能:在某个区域中查找你要找的字符,一旦找到就定位到第一个对应的单元格.所以Find函数的返回值是个单元格,也就是个range值.举例,s ...
- 第三篇——软件之殇,WE ARE THOUSANDS APART!
软件工程是一门工程性的学科,其目标主要是成功地建造一个大型软件系统.这其中包括:付出较低的开发成本:达到要求的软件功能:取得较好的软件性能:开发的软件易于移植:需要较低的维护费用:能按时完成开发任务, ...
- 关于解析P D X P 协议的心得
1一个线程进队Quee 一个线程出队 也应该lock,不然会出错. 2 委托的效率较低 能不用委托的地方,尽量不要用委托. 在一个线程中需要调用控件时采用委托. 3 for循环中异步发送数据不能保证发 ...
- 关于spring中无法将service注入到servlet中的问题
首先,servlet是动态网页项目区别于普通的java项目的,是动态网页项目中web.xml主要配置文件管理的,而spring只能管理普通的pojo,而没办法直接注入,尽管你的注入方式和配置方式都没有 ...
- Android深度探索--HAL与驱动开发----第六章读书笔记
Linux驱动程序与其他类型的Linux程序一样拥有自己的规则,下面给出一个编写基本的Linux驱动的一般步骤: (1)建立Linux驱动的骨架(装载和卸载Linux驱动): (2)注册和注销设备文件 ...
- ubuntu用下载的文件替换即可更新
./usr/lib/flashplugin-installer/libflashplayer.so 也有可能是 /usr/lib/firefox-addons/plugins
- javaweb学习总结 servlet开发(一)
转载:http://www.cnblogs.com/xdp-gacl/p/3760336.html 这里主要是将其加入自己的理解过一遍. 这里的代码全在eclipse java ee中执行的. 一.s ...