gpt4 book ai didi

angular - 在 Angular2 中如何仅将类添加到第一行

转载 作者:太空狗 更新时间:2023-10-29 18:05:56 24 4
gpt4 key购买 nike

我想根据某些条件添加一个 css 类。

在下面的代码中,我想将 RowHeaderCSS 类添加到表格的第一行,但它确实有效。谁能帮我解决这个问题?

<tr *ngFor="let dataObject of dataCollection;let isFirstRow=(index==1?true:false)" [ngClass]="{'RowHeaderCSS':isFirstRow)}">
<td scope="row">{{dataObject.SNO}}</td>
<td Overdue-Bucket-Template>{{dataObject.MONTH01}}</td>
<td Overdue-Bucket-Template>{{dataObject.MONTH02}}</td>
</tr>

最佳答案

Angular 有一个局部变量 first 用于所有 ngFor 循环,它会做你想做的事情

<tr *ngFor="let dataObject of dataCollection; let isFirstRow=first" [ngClass]="{'RowHeaderCSS' : isFirstRow}">
<td scope="row">{{dataObject.SNO}}</td>
<td Overdue-Bucket-Template>{{dataObject.MONTH01}}</td>
<td Overdue-Bucket-Template>{{dataObject.MONTH02}}</td>
</tr>

https://angular.io/api/common/NgForOf

Local Variables

NgFor provides several exported values that can be aliased to local variables:

  1. index The index of the current item in the iterable.
  2. first True when the item is the first item in the iterable.
  3. last True when the item is the last item in the iterable.
  4. even True when the item has an even index in the iterable.
  5. odd True when the item has an odd index in the iterable.

关于angular - 在 Angular2 中如何仅将类添加到第一行,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/42483695/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com