admin管理员组文章数量:1326112
It could be silly but how do I do something like this in angular 2 in a cleaner way? (Avoiding the string concatenation)
<div [class]="'indicator indicator-circle ' + colorClass"></div>
Explanation :
I want to add two static classes indicator
& indicator-circle
at all times but I also want the colorClass
to be applied which is an input from the ponent class.
It could be silly but how do I do something like this in angular 2 in a cleaner way? (Avoiding the string concatenation)
<div [class]="'indicator indicator-circle ' + colorClass"></div>
Explanation :
I want to add two static classes indicator
& indicator-circle
at all times but I also want the colorClass
to be applied which is an input from the ponent class.
3 Answers
Reset to default 6You could leverage the ngClass
directive with an array:
<div [ngClass]="['indicator', 'indicator-circle', colorClass]"></div>
See this link for more details:
- https://angular.io/docs/ts/latest/api/mon/index/NgClass-directive.html
You can use ngClass
<div class="indicator indicator-circle" [ngClass]="colorClass"></div>
You need to put only colorClass
in [ngClass]/[attr.class]/[class]
property binding
<div class="indicator indicator-circle" [ngClass]="colorClass"></div>
本文标签: javascriptCleaner way to add both static and variable class in html in Angular 2Stack Overflow
版权声明:本文标题:javascript - Cleaner way to add both static and variable class in html in Angular 2 - Stack Overflow 内容由网友自发贡献,该文观点仅代表作者本人, 转载请联系作者并注明出处:http://www.betaflare.com/web/1742192610a2430487.html, 本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌抄袭侵权/违法违规的内容,一经查实,本站将立刻删除。
发表评论