[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 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>
时间: 2024-08-27 19:18:20

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

模板特化和偏模板特化例子(template specialization and partial template specialization)

测试环境: win7 64 g++ 4.8.1 /*********************************************************************************   Copyright (C), 1988-1999, drvivermonkey. Co., Ltd.   File name:    Author: Driver Monkey   Version:    Mail:[email protected]   Date: 2014.04

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

String Template(字符串模板)在很多编程语言和框架中都支持,是一个很有用的特性.本文将Jerry工作中使用到的String Template的特性做一个总结. ES6 阮一峰老师有一个专门的网站介绍ES6入门,还出了一本书: <ECMAScript6标准入门>. http://es6.ruanyifeng.com/ 我们来看看ES6里的String Template. 首先看下面这段代码. <html> <div id="JerryTest"

[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 your template. // letterSelect.ts import {Component, View, FORM_DIRECTIVES, NgFor} from 'angular2/angular2'; @Component({ selector: 'letter-select' }) @

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

测试环境: win7 64 g++ 4.8.1 /*********************************************************************************   Copyright (C), 1988-1999, drvivermonkey. Co., Ltd.   File name:    Author: Driver Monkey   Version:    Mail:[email protected]   Date: 2014.04

[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 use the data throughout your application so that your data is consistent and in sync. Create a service.module.ts: import { NgModule} from '@angular/co

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

如何使用模板系统 在Python代码中使用Django模板的最基本方式如下: 可以用原始的模板代码字符串创建一个 Template 对象, Django同样支持用指定模板文件路径的方式来创建 Template 对象; 调用模板对象的render方法,并且传入一套变量context.它将返回一个基于模板的展现字符串,模板中的变量和标签会被context值替换. ——————————————————————————————基本方法———————————————————————————————————

Zabbix3.2下Template App Zabbix Server+Template OS Linux Item

序号 Name Key 返回值 释义1 Agent ping agent.ping 1 就是ping一下2 Avaliable memory vm.memory.size[available] 563798016 可用的内存大小3 Checksum of /etc/passwd vfs.file.cksum[/etc/passwd]  3395042901 通过文件的cksum码检测完整性4 Context switches per second system.cpu.switches 1808

Mixed Content: xxx This request has been blocked; the content must be served over HTTPS.

在升级https的过程中,出现如下问题: Mixed Content: The page at 'https://www.xxx.com/denglu.html' was loaded over HTTPS, but requested an insecure script 'http://qzonestyle.gtimg.cn/qzone/openapi/qc-1.0.1.js'. This request has been blocked; the content must be serve

The template engine

Play has an efficient templating system which allows to dynamically generate HTML, XML, JSON or any text-based formatted document. The template engine uses Groovy as an expression language. A tag system allows you to create reusable functions. Templa