根据条件在 Angular Ionic 中使用 ngFor 突出显示行
Highlight rows using ngFor in Angular Ionic based on condition
在我的应用程序中,我需要在 angular 中使用 ngfor 根据计数值突出显示所有行。
我试过了,根据我的 count.Please 帮助
,我只能突出显示特定的行
https://stackblitz.com/edit/ionic-ypxtr7?file=app%2Fapp.component.ts
如果我的计数值为 3,我需要突出显示索引为 0、1 和 2 的行。
改变
[ngClass]="(count-1==i)?'newMsg':'oldMsg'"
到
[ngClass]="(count-1>=i)?'newMsg':'oldMsg'"
你也可以传递一个函数,比如
[ngClass]="isNew(i)?'newMsg':'oldMsg'"
而在组件中
isNew(index) {
if (index < this.count) {
return true;
}
return false;
}
在我的应用程序中,我需要在 angular 中使用 ngfor 根据计数值突出显示所有行。
我试过了,根据我的 count.Please 帮助
,我只能突出显示特定的行https://stackblitz.com/edit/ionic-ypxtr7?file=app%2Fapp.component.ts
如果我的计数值为 3,我需要突出显示索引为 0、1 和 2 的行。
改变
[ngClass]="(count-1==i)?'newMsg':'oldMsg'"
到
[ngClass]="(count-1>=i)?'newMsg':'oldMsg'"
你也可以传递一个函数,比如
[ngClass]="isNew(i)?'newMsg':'oldMsg'"
而在组件中
isNew(index) {
if (index < this.count) {
return true;
}
return false;
}