2017-11-30 10 views
1

?例えば。残りの部分がdude_1になると、最初のインデックスはdude_0クラスになりますか?角度テンプレートは、私はこのコードを持ってitersを使用してクラスを適用し、* ngFor

<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> 
+1

可能な重複:// stackoverflow.com/questions/37090877/dynamic-classname-inside-ngclass-in-angular-2) –

答えて

2

最初に、[ngClass]

<thead> 
    <th [ngClass]="{'dude_0': i==0, 'dude_1': i>0}" *ngFor="let tp of column_names;let i=index">{{tp}}</th> 
</thead> 
3
<th *ngFor="let tp of column_names; index as index" [class.dude_0]="index === 0" 
    [class.dude_1]="index > 0">{{tp}}</th> 

、あるいは単純に使用します。https([角度2でngClass内部の動的クラス名]の

<th *ngFor="let tp of column_names; first as first" [class.dude_0]="first" 
    [class.dude_1]="!first">{{tp}}</th>