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 ...
随机推荐
- ArcEngine 栅格数据
1.ArcEngine中的栅格数据组织方式(详细信息见:http://resources.arcgis.com/zh-cn/help/main/10.1/index.html#/na/009t0000 ...
- SET-UID程序漏洞实验
一.实验描述 Set-UID 是Unix系统中的一个重要的安全机制.当一个Set-UID程序运行的时候,它被假设为具有拥有者的权限.例如,如果程序的拥有者是root,那么任何人运行这个程序时都会获得程 ...
- 如何在网页中调用百度地图api
我想在木有提供地图接口的年代,前端工程师门要么只写上企业的具体地址,要么就是用一张标有自己位置的地图图片.但是现在不一样啦!为了增强用户体验,谷歌,甚至百度都很开放了,你可以在他们的网站上找到地图接口 ...
- 安装lnmp一键安装包(转)
系统需求: CentOS/RHEL/Fedora/Debian/Ubuntu/Raspbian Linux系统 需要3GB以上硬盘剩余空间 128M以上内存,Xen的需要有SWAP,OpenVZ的另外 ...
- Linq中关键字的作用及用法
Linq中关键字的作用及用法 1.All:确定序列中的所有元素是否都满足条件.如果源序列中的每个元素都通过指定谓词中的测试,或者序列为空,则为 true:否则为 false. Demo: 此示例使用 ...
- JPA原理理解
从前面一篇<JPA使用入门>了解了JPA的简单使用.要想继续深入的使用JPA,可能了解一点原理对于学习JPA会比较有益处. 这里从JPA的功能来简单阐述JPA的原理. 从<初步了解J ...
- 【python】闭包、@修饰符(装饰器)、
闭包:(返回函数的行为叫闭包??) #函数也是对象,所以可以被传递 def line_conf(a,b): def line(x): return a*x+b return line line1=li ...
- swift 命名,字符串
命名: let numberOfDogs = 6 +2; 字符串连接: let finishedMessage = username + "xx" + password; 字符串 ...
- window上利用pip安装pandas
官网推荐的是直接使用Anoconda,它集成了pandas,可以直接使用.安装挺简单的,有windows下的安装包.如果不想安装庞大的Anoconda,那就一步一步用pip来安装pandas.下面我主 ...
- j2ee学习资料收集
1 tomcat web.xml加载顺序, 讲解了web.xml什么时候加载,内部的各个组件加载的顺序 http://blog.sina.com.cn/s/blog_4553489c01010 ...