user3025289
user3025289

Reputation:

How to avoid repetitions within Angular ngClass?

Imagine following situation:

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

All these CSS-Classes cSmall, cGray, cTab1 are depended on !first.

Can I avoid unnecessary repetitions within:

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

I've alredy tried { [cSmall,cGray,cTab1]: !first } with no success :)

Upvotes: 2

Views: 99

Answers (2)

mgm87
mgm87

Reputation: 894

Try this: [ngClass]="{ 'cSmall cGray cTab1': !first }"

Upvotes: 2

Akshay Rana
Akshay Rana

Reputation: 1485

Try

<some-element [ngClass]="{'class1 class2 class3' : true}">...</some-element>

Reference : NgClass API

Upvotes: 2

Related Questions