Conditional color


#1

Hello,

I would like to set the color of an element dynamically. I tried to do it like this<ion-content [ngStyle]=" { 'color' : 'api.getCategoryColor(item.categories[0])'}"> but it doesn’t work.

Does anybody knows how I could do it ?

Thank you


#2

You can bind [style.color], but do so only to a property. Always do whatever you can to avoid function calls in template expressions: they are a major source of bad performance.


#3

Hello, thank for your answer. It doesn’t work when setting it with api.getCategoryColor[0]. If I set it like “blue” it works :
<ion-row [style.border]="'solid 1px ' + 'blue'" >