问题
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>
回答1:
Add a +
and a space:
<div *ngFor="let classVar of classList" >
<span [ngClass]="'myClass ' + classVar"></span>
</div>
回答2:
You can use it like :
[ngClass]="'myClass' + classVar "
OR
ngClass="myClass {{ classVar }}"
OR
[class]="'myClass' + classVar "
OR
class="myClass {{ classVar }}"
来源:https://stackoverflow.com/questions/49026960/concat-classname-with-variable-angular-2