欧美bbbwbbbw肥妇,免费乱码人妻系列日韩,一级黄片

淺談Angular2 ng-content 指令在組件中嵌入內(nèi)容

 更新時(shí)間:2017年08月18日 14:30:06   作者:坐在那邊看天空  
本篇文章主要介紹了淺談Angular2 ng-content 指令在組件中嵌入內(nèi)容,具有一定的參考價(jià)值,有興趣的可以了解一下

ng-content指令可以在組件中嵌入模板代碼,方便定制可復(fù)用的組件。

比如:頁面的header是個(gè)通用組件,導(dǎo)航菜單樣式已經(jīng)設(shè)定好,只需在header標(biāo)簽內(nèi)加上菜單內(nèi)容。

用ng-content標(biāo)簽,將父組件模板中包含的menu標(biāo)簽內(nèi)容加到指定位置。select屬性支持css選擇器,如:"#id",".class","[name=value]"等

header組件的模板:

<p>
 {{title}}
</p>
<p><input type="checkbox" name="cb" [(ngModel)]="isChecked" (click)="toggle()" />Checkbox <br /></p>
<ng-content select="menu"></ng-content>

父組件使用方法:

<app-header #header [title]="title" name="{{name}}" (checkEmitter)="onCheckedChange($event)" >
 <menu>
  <ul>
   <li>aa</li>
   <li>bb</li>
   <li>cc</li>
  </ul>
 </menu>
</app-header>
<app-header #header2 [title]="title2" name="{{name}}" (checkEmitter)="onCheckedChange($event)" ></app-header>
<button (click)="header.toggle()">通過本地變量調(diào)用子組件方法</button>
<button (click)="headerToggle()">通過ViewChild調(diào)用子組件方法</button>

以上就是本文的全部內(nèi)容,希望對(duì)大家的學(xué)習(xí)有所幫助,也希望大家多多支持腳本之家。

相關(guān)文章

最新評(píng)論