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. 面向对象(OO)基础

    面向对象,英文Object-Oriented,简称OO),另外相关的还有:面向对象分析(Object-Oriented Analysis,OOA) 面向对象设计(Object-Oriented Des ...

  2. CSS盒子模型图

    下面这张图,是W3C标准的CSS盒子模型: 由上图可以清楚的看出各个部分的CSS属性.

  3. Java开发常用的代码片段

    1. 字符串有整型的相互转换 String a = String.valueOf(2);   //integer to numeric string  int i = Integer.parseInt ...

  4. 洛谷P1720 月落乌啼算钱

    目背景 (本道题目木有以藏歌曲……不用猜了……) <爱与愁的故事第一弹·heartache>最终章. 吃完pizza,月落乌啼知道超出自己的预算了.为了不在爱与愁大神面前献丑,只好还是硬着 ...

  5. C/C++(结构体)

    结构体(struct) 从某种意义上说,会不会使用struct,如何使用struct是区别一个开发人员是否具备丰富开发经验的试金石. 处理由不同类型成员构成的构造类型,要采用结构体的方式. 定义:关键 ...

  6. at&&atq&&atrm---定时任务

    at放在 ls /var/spool/at/ 目录下 At的配置文件/etc/at.deny和/etc/at.allow 如果deny单独存在,则是deny以为的所有用户都可以使用at命令 如果all ...

  7. Python day4知识回顾

    # -*- coding: utf_8 _*_# Author:Vi#字典是无序的 info = { 'student001':"DIO", 'student002':" ...

  8. x264代码剖析(八):encode()函数之x264_encoder_close()函数

    x264代码剖析(八):encode()函数之x264_encoder_close()函数 encode()函数是x264的主干函数.主要包含x264_encoder_open()函数.x264_en ...

  9. HDU 2102 A计划 (三维的迷宫BFS)

    题目链接:pid=2102">传送门 题意: 三维的一个迷宫,起点在第一层的S(0,0,0)处,问是否能在规定的时间内走到第二层的P 处.'*'代表不能走,'.'代表能够走,'#'代表 ...

  10. 淘宝的css初始化代码

    ;; } body, button, input, select, textarea { font:12px/1.5tahoma, arial, \5b8b\4f53; } h1, h2, h3, h ...