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,406
  • 4
  • 16
  • 40

2 Answers2

21

Add a + and a space:

<div *ngFor="let classVar of classList" >
  <span [ngClass]="'myClass ' + classVar"></span>                
</div>
Chrillewoodz
  • 25,080
  • 21
  • 84
  • 163
11

You can use it like :

[ngClass]="'myClass' + classVar "

OR

ngClass="myClass {{ classVar }}"

OR

[class]="'myClass' + classVar "

OR

class="myClass {{ classVar }}"
Vivek Doshi
  • 52,153
  • 9
  • 101
  • 113
  • 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