12

I want something like class = "myClass {{classVar}}"

I am trying to concat class name with variable value in scope but not working.

<div *ngFor="let classVar of classList" >
  <span [ngClass]="'myClass' classVar "></span>                
</div>
Dipak Telangre
  • 1,792
  • 4
  • 19
  • 46

2 Answers2

22

Add a + and a space:

<div *ngFor="let classVar of classList" >
  <span [ngClass]="'myClass ' + classVar"></span>                
</div>
Chrillewoodz
  • 27,055
  • 21
  • 92
  • 175
11

You can use it like :

[ngClass]="'myClass' + classVar "

OR

ngClass="myClass {{ classVar }}"

OR

[class]="'myClass' + classVar "

OR

class="myClass {{ classVar }}"
Vivek Doshi
  • 56,649
  • 12
  • 110
  • 122
  • 1
    Is where any difference between `[ngClass]="'myClass' + classVar "` and `[class]="'myClass' + classVar "`??? – Gil Epshtain Dec 20 '18 at 13:24
  • @GilEpshtain seems you can find your answer here: https://stackoverflow.com/a/45321551/2118777 – Pipo Jan 27 '20 at 10:45