Angular2, class runtime binding

53 views
Skip to first unread message

cool...@gmail.com

unread,
Jul 7, 2015, 3:52:39 PM7/7/15
to ang...@googlegroups.com
Angular2 can bind css class as follows `[class.fa-train]="true"`, but can I bind them at runtime (something like `[class[key]]="true"`) ? For example, I have an array:
```javascript
['fa-train', 'fa-subway', 'fa-bed']
```
I would like to convert them as follows:
```javascript
<i class="fa fa-train"></i>
<i class="fa fa-subway"></i>
<i class="fa fa-bed"></i>
```

Thanks.

Sander Elias

unread,
Jul 8, 2015, 2:12:47 AM7/8/15
to ang...@googlegroups.com
Hi,

How about:
<i [class]="{{['fa-train', 'fa-subway', 'fa-bed'].join(' ')}}>

Regards
Sander
Reply all
Reply to author
Forward
0 new messages