Angular 1 provided a mechanism to place content from your template inside of another template called transclusion. This concept has been brought into Angular 2 and was renamed to content projection and given super powers.

In this lesson learn how to setup content projection and upgrade it to support multiple projections with encapsulated functionality.

ng-content, just like Angular1 transclude, in ng-content, you can add 'select' attr to do content projection:

<ng-content select=".header"></ng-content>
<div class="result-list">
<md-list >
<md-list-item *ngFor="let item of searchResult">
{{item}}
</md-list-item>
<md-list-item *ngIf="searchResult?.length === 0">No result...</md-list-item>
<md-list-item *ngIf="!searchResult">List here...</md-list-item>
</md-list>
</div>
<ng-content select="footer"></ng-content>

Using:

<result-list [keys]="items" [urls]="urls" class="list">
<div class="header">Search result: </div>
<footer>End...</footer>
</result-list>

[Angular 2] Share Template Content In Another Template With Content Projection <ng-content>的更多相关文章

  1. Deferred content load was not performed. To provide the content, subscribe to the View's QueryControl event

    {"Deferred content load was not performed. To provide the content, subscribe to the View's Quer ...

  2. content is not supported outside 'script" or asp content' region

    https://stackoverflow.com/questions/48915080/asp-net-content-is-not-supported-outside-the-script-or- ...

  3. ES6, Angular,React和ABAP中的String Template(字符串模板)

    String Template(字符串模板)在很多编程语言和框架中都支持,是一个很有用的特性.本文将Jerry工作中使用到的String Template的特性做一个总结. ES6 阮一峰老师有一个专 ...

  4. [Angular 2] Exposing component properties to the template

    Showing you how you can expose properties on your Controller to access them using #refs inside of yo ...

  5. Azure ARM (5) ARM Template初探 - 本地JSON Template文件(1)

    <Windows Azure Platform 系列文章目录>      Azure ARM (1) 概览      Azure ARM (2) 概览      Azure ARM (3) ...

  6. [Angular 2] Share a Service Across Angular 2 Components and Modules

    Services are used to share data between components. They follow a module pattern that allows you to ...

  7. <转载>模板声明中template <typename T>和template <class T>

    原文地址http://blog.csdn.net/bug07250432/article/details/10150625 在c++Template中很多地方都用到了typename与class这两个 ...

  8. 模板专业化和模板偏特样片(template specialization and partial template specialization)

    测试环境: win7 64 g++ 4.8.1 /*************************************************************************** ...

  9. Django——如何使用Template以及如何向template传递变量

    如何使用模板系统 在Python代码中使用Django模板的最基本方式如下: 可以用原始的模板代码字符串创建一个 Template 对象, Django同样支持用指定模板文件路径的方式来创建 Temp ...

随机推荐

  1. LinkedIn微服务框架rest.li

    linkedin/rest.li  https://github.com/linkedin/rest.li LinkedIn微服务框架rest.li摘要:Rest.li是一款REST+JSON框架,使 ...

  2. SqlDatasource简单用法

    http://blog.csdn.net/zxf1by1/article/details/7055015 增删改查和前台页面(拖拽过来的,但是包含参数的)

  3. Statement和ResultSet

    statement.prepareStatement.callableStatement的使用 1.带?参数的使用prepareStatement.这也是使用最多的. 2.不带参数,例如查所用,不需要 ...

  4. 51Nod 迷宫问题(最短路+权值)(模板)

    你来到一个迷宫前.该迷宫由若干个房间组成,每个房间都有一个得分,第一次进入这个房间,你就可以得到这个分数.还有若干双向道路连结这些房间,你沿着这些道路从一个房间走到另外一个房间需要一些时间.游戏规定了 ...

  5. ajax关于主流中的异类:应对Opera(四)

    修改示例以支持Opera <!DOCTYPE html> <html> <head> <meta charset="utf-8" /> ...

  6. Centos安装FastDFS+Nginx(一天时间搞定)

    最近在研究和使用Fastdfs,别人搭的环境,终究是别人的,绝知此事要躬行~躬行啊~      下面的脚本主要参考了官方的INSTALL文件,这个是比较权威的,部分地方和实际情况不一致.比如配置文件的 ...

  7. 洛谷 P1506 拯救oibh总部

    P1506 拯救oibh总部 题目背景 oibh总部突然被水淹没了!现在需要你的救援…… 题目描述 oibh被突来的洪水淹没了>.<还好oibh总部有在某些重要的地方起一些围墙,用*号表示 ...

  8. ZOJ 2301 Color the Ball 线段树(区间更新+离散化)

    Color the Ball Time Limit: 2 Seconds      Memory Limit: 65536 KB There are infinite balls in a line ...

  9. BZOJ1503: [NOI2004]郁闷的出纳员(Splay)

    Description OIER公司是一家大型专业化软件公司,有着数以万计的员工.作为一名出纳员,我的任务之一便是统计每位员工的 工资.这本来是一份不错的工作,但是令人郁闷的是,我们的老板反复无常,经 ...

  10. Android触摸事件(五)-CropBitmapActivity关于裁剪工具的使用

    文件夹 文件夹 概述 传递数据 裁剪流程 其他事项 使用方式 图片辅助功能 图片缩略图载入 图片旋转 源代码 GitHub地址 演示样例GIF 概述 这个Activity是为了裁剪图片的.使用时须要提 ...