Concat classname with variable Angular 2

别来无恙 提交于 2020-03-21 17:49:29

问题


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

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!