Angular2, class runtime binding

53 ogledov
Preskoči na prvo neprebrano sporočilo

cool...@gmail.com

neprebran,
7. jul. 2015, 15:52:397. 7. 15
do 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

neprebran,
8. jul. 2015, 02:12:478. 7. 15
do ang...@googlegroups.com
Hi,

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

Regards
Sander
Odgovori vsem
Odgovori avtorju
Posreduj
0 novih sporočil