【问题标题】:Highlight rows using ngFor in Angular Ionic based on condition根据条件在Angular Ionic中使用ngFor突出显示行
【发布时间】:2020-02-26 06:03:42
【问题描述】:

在我的应用程序中,我需要使用 ngfor 在角度中突出显示所有基于计数值的行。

我试过了,我只能根据我的计数突出显示特定的行。请帮助

https://stackblitz.com/edit/ionic-ypxtr7?file=app%2Fapp.component.ts

如果我的计数值为 3,我需要突出显示索引为 0、1 和 2 的行。

【问题讨论】:

    标签: javascript css angular typescript ionic3


    【解决方案1】:

    改变 [ngClass]="(count-1==i)?'newMsg':'oldMsg'"[ngClass]="(count-1>=i)?'newMsg':'oldMsg'"

    【讨论】:

      【解决方案2】:

      你也可以传递一个函数

      [ngClass]="isNew(i)?'newMsg':'oldMsg'"
      

      在组件中

      isNew(index) {
            if (index < this.count) {
              return true;
            }
            return false;
          }
      

      【讨论】:

        猜你喜欢
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        • 2019-09-08
        • 2023-03-13
        相关资源
        最近更新 更多