angular ng-container
生活随笔
收集整理的這篇文章主要介紹了
angular ng-container
小編覺(jué)得挺不錯(cuò)的,現(xiàn)在分享給大家,幫大家做個(gè)參考.
Angular 的 <ng-container> 是一個(gè)分組元素,它不會(huì)干擾樣式或布局,因?yàn)?Angular 不會(huì)將其放置在 DOM 中。
為沒(méi)有DOM元素得指令安排宿主
當(dāng)沒(méi)有單個(gè)元素承載指令時(shí),可以使用 <ng-container>
//使用 <ng-container> 的條件化段落 <p>I turned the corner<ng-container *ngIf="hero">and saw {{hero.name}}. I waved </ng-container> and continued on my way. </p> //要有條件地排除 <option>,請(qǐng)將 <option> 包裹在 <ng-container> 中 <select [(ngModel)]="hero"><ng-container *ngFor="let h of heroes"><ng-container *ngIf="showSad || h.emotion !== 'sad'"><option [ngValue]="h">{{h.name}} ({{h.emotion}})</option></ng-container></ng-container> </select>總結(jié)
以上是生活随笔為你收集整理的angular ng-container的全部?jī)?nèi)容,希望文章能夠幫你解決所遇到的問(wèn)題。
- 上一篇: angular 指令
- 下一篇: angular中的依赖注入