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. 4.cocos场景和层的调用

    调用关系: AppDeligate.cpp bool AppDelegate::applicationDidFinishLaunching() { // initialize director aut ...

  2. Looksery Cup 2015

    A题水 C题 博弈论,如果不是CF有WA具体哪个点错了和数据的话,AC要难许多. 如果D的操作数大于奇数个数直接Win 偶数个数大于等于n – k 时,S直接Win 偶数个数小于n – k时,若D操作 ...

  3. nginx配置静态文件服务器的一个特殊需求的探索和分享, nginx处理不同路径返回统一文件,nginx改写,跳转请求.

    最近在做一个前后端分离的个人博客,在做自己博客的时候有个想法,本来是打算用nginx作为静态文件服务器使用,django做后端程序. 我的前端页面用vue写的,结果用组件用嗨了,发现页面列表和 详情都 ...

  4. cron 简单任务调度 go

    package main import ( "github.com/robfig/cron" "log" ) func main() { i := 0 c := ...

  5. Matlab piecelin

    function v = piecelin(x,y,u) %PIECELIN Piecewise linear interpolation. % v = piecelin(x,y,u) finds t ...

  6. Android开发经验一判断当前屏幕是全屏还是非全屏

    public void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); setContentView ...

  7. 随时查看源码的网站---http://www.sooset.com/

    由于工作需要经常要在Windows平台下参阅linux源码,以前都用http://lxr.linux.no/来浏览源码(如下图所示),最近发现sooset来浏览更方便,所以介绍给大家分享. 650) ...

  8. cookie和session笔记

    1.http协议是无连接的,即每一次http请求都是新的,和上一次没有联系,这不利于和用户的交互.针对这一缺点产生了cookie. 2.cookie是一段保存在客户端上的验证信息,同一个域使用同一个c ...

  9. Vue框架学习笔记

    <div id="app"> </div> var app = new Vue({ el:"#app", // 绑定的元素 data:{ ...

  10. Android 调试出现 could not get wglGetExtensionsStringARB

    解决 AVD Manager -> 选择模拟器 -> 点击 Edit看 Enabled 是不是被选中了.是的话取消选中,OK.希望对你实用.