![](/img/trans.png)
[英]Can I apply a template to a object-variable of a ngFor - loop in Angular?
[英]Angular template apply class using iters and *ngFor
我有以下代碼:
<thead>
<th class="dude" *ngFor="let tp of column_names;let i=index">{{tp}}</th>
</thead>
如何應用基於索引的類? 例如,當其余索引獲取dude_1時,第一個索引獲取dude_0類?
例如
<thead>
if i==0
<th class="dude_0" *ngFor="let tp of column_names;let i==index"{{tp}}</th>
if i>0
<th class="dude_1" *ngFor="let tp of column_names;let i=index"{{tp}}</th>
</thead>
<th *ngFor="let tp of column_names; index as index" [class.dude_0]="index === 0"
[class.dude_1]="index > 0">{{tp}}</th>
甚至更簡單,首先:
<th *ngFor="let tp of column_names; first as first" [class.dude_0]="first"
[class.dude_1]="!first">{{tp}}</th>
使用[ngClass]
<thead>
<th [ngClass]="{'dude_0': i==0, 'dude_1': i>0}" *ngFor="let tp of column_names;let i=index">{{tp}}</th>
</thead>
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.