如何避免在Angular ngClass中重复?

问题描述 投票:2回答:2

想象以下情况:

 <div *ngFor="let d of dm; first as first">
    <span
      [ngClass]="{ cSmall: !first, cGray: !first, cTab1: !first }"
    >
      {{ d }}
    </span>
  </div>

所有这些CSS类cSmall, cGray, cTab1都取决于!first

我是否可以避免不必要的重复:

{ cSmall: !first, cGray: !first, cTab1: !first }

我已经尝试过{ [cSmall,cGray,cTab1]: !first },但没有成功:)

angular styling ng-class angular-ng-class
2个回答
3
投票

尝试


3
投票

尝试一下:[ngClass]="{ 'cSmall cGray cTab1': !first }"

© www.soinside.com 2019 - 2024. All rights reserved.