Concat classname with variable Angular 2

Dipak Telangre picture Dipak Telangre · Feb 28, 2018 · Viewed 9.9k times · Source

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>

Answer

Chrillewoodz picture Chrillewoodz · Feb 28, 2018

Add a + and a space:

<div *ngFor="let classVar of classList" >
  <span [ngClass]="'myClass ' + classVar"></span>                
</div>