You have complete control over the elements you nest inside of your component instance by using selectors to access and rearrange them. Selecting allows you reconstruct the elements in whatever order you like so you can visual customize the content passed in.

You can pass multi elmenents into ng-content:

home.ts:

@Component({
selector: 'home',
template: `
<widget-two> <h2>Title</h2>
<div>Some content</div>
<h3>Footer</h3> </widget-two>
`
})

widget-two.ts:

@Component({
selector: 'widget-two',
styles:[`
:host{
display: block;
border: 3px solid red;
}
`],
template: `
<h2>Above</h2>
<ng-content ></ng-content>
<h2>Below</h2>
`
})

So all three element will be passed into ng-content:

<h2>Title</h2>
<div>Some content</div>
<h3>Footer</h3>

ng-content can add "select" attr, you can use "element tag", "attr", "class / id":

@Component({
selector: 'home',
template: `
<widget-two> <h2 header>Title</h2> <!-- attr -->
<div class="content">Some content</div> <!-- class -->
<h3>Footer</h3> <!-- tag --> </widget-two>
`
})
@Component({
selector: 'widget-two',
styles:[`
:host{
display: block;
border: 3px solid red;
}
`],
template: `
<h2 >Above</h2>
<ng-content select="h3"></ng-content> <!-- tag h3 --> footer-->
<ng-content select="[header]"></ng-content> <!--attr h2 --> Title -->
<ng-content select=".content"></ng-content> <!-- class--->
<h2>Below</h2>
`
})

[Angular 2] Select From Multiple Nested Angular 2 Elements的更多相关文章

  1. angular实现select的ng-options4

    ng实现简单的select <div ng-controller="ngSelect"> <select ng-model="vm.selectVal& ...

  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. NEST - How can i do multiple nested aggregation?

    question: How can I do multiple nested aggregation? I have tried something like this: Aggregations(x ...

  6. select标签multiple属性的用法

    前些日子公司让做一个功能模块.对于里面一个小功能费了些周折,现将其总结一下: 一.实现效果: watermark/2/text/aHR0cDovL2Jsb2cuY3Nkbi5uZXQvZ2FvaHVh ...

  7. Angular 从入坑到挖坑 - Angular 使用入门

    一.Overview angular 入坑记录的笔记第一篇,完成开发环境的搭建,以及如何通过 angular cli 来创建第一个 angular 应用.入坑一个多星期,通过学习官方文档以及手摸手的按 ...

  8. [从 0 开始的 Angular 生活]No.38 实现一个 Angular Router 切换组件页面(一)

    前言 今天是进入公司的第三天,为了能尽快投入项目与成为团队可用的战力,我正在努力啃官方文档学习 Angular 的知识,所以这一篇文章主要是记录我如何阅读官方文档后,实现这个非常基本的.带导航的网页应 ...

  9. Angular项目构建指南 - 不再为angular构建而犹豫不决(转)

    如果你不知道什么是Angular或者根本没听说过,那么我接下来所说的对你来说毫无益处,不过如果你打算以后会接触Angular或者干脆要涨涨姿势~读下去还是有点用的. Angular和它之前所出现的其余 ...

随机推荐

  1. 八皇后问题 --- 递归解法 --- java代码

    八皇后问题是一个以国际象棋为背景的问题:如何能够在 8×8 的国际象棋棋盘上放置八个皇后,使得任何一个皇后都无法直接吃掉其他的皇后?为了达到此目的,任两个皇后都不能处于同一条横行.纵行或斜线上.八皇后 ...

  2. 通过xshell 设置代理上网

    前言: 前段时间,选修了一门并行计算,老师给我们每个人分配了一个linux登录账号,通过这个账号,可能登录学校的一台linux . 一次偶然的机会,了解到可以通过xshell , ssh服务器给本地开 ...

  3. (phpmyadmin error)Login without a password is forbidden by configuration (see AllowNoPassword) in ubuntu

    1.Go to /etc/phpmyadmin/config.inc.php and open it your favorite editor. 2.Search for below line of ...

  4. [Cocos2d-JS] 安卓机器的几个按钮

    cc.eventManager.addListener({ event:cc.EventListener.KEYBOARD, onKeyPressed:function(keycode,event){ ...

  5. 无线网WEP的安全测试及防范

    650) this.width=650;" border="0" alt="" src="http://img1.51cto.com/att ...

  6. 深入浅出谈存储之NAS是什么

    深入浅出谈存储之NAS是什么 2012年02月17日16:42 来源:新浪博客 作者:林沛满 编辑:曾智强 查看全文 赞(0)评论(0) 分享 标签: NAS , 企业NAS , 存储系统 [IT16 ...

  7. 转】Mahout学习路线图

    原博文出自于: http://blog.fens.me/hadoop-mahout-roadmap/ 感谢! Mahout学习路线图 Hadoop家族系列文章,主要介绍Hadoop家族产品,常用的项目 ...

  8. 为什么在Spring的配置里,最好不要配置xsd文件的版本号

    为什么dubbo启动没有问题? 原文链接:http://www.tuicool.com/articles/YRn67zM 这篇blog源于一个疑问: 我们公司使了阿里的dubbo,但是阿里的开源网站h ...

  9. uestc oj 1217 The Battle of Chibi (dp + 离散化 + 树状数组)

    题目链接:http://acm.uestc.edu.cn/#/problem/show/1217 给你一个长为n的数组,问你有多少个长度严格为m的上升子序列. dp[i][j]表示以a[i]结尾长为j ...

  10. hdoj 5392 Infoplane in Tina Town

    题目链接:http://acm.hdu.edu.cn/showproblem.php?pid=5392 #include<stdio.h> #include<cstring> ...