Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Concat classname with variable Angular 2

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>
like image 729
Dipak Telangre Avatar asked Feb 28 '18 10:02

Dipak Telangre


2 Answers

Add a + and a space:

<div *ngFor="let classVar of classList" >
  <span [ngClass]="'myClass ' + classVar"></span>                
</div>
like image 195
Chrillewoodz Avatar answered Oct 22 '22 18:10

Chrillewoodz


You can use it like :

[ngClass]="'myClass' + classVar "

OR

ngClass="myClass {{ classVar }}"

OR

[class]="'myClass' + classVar "

OR

class="myClass {{ classVar }}"
like image 27
Vivek Doshi Avatar answered Oct 22 '22 18:10

Vivek Doshi