I have an ion-item. I send color from backend. Now I want to attach background color with [ngStyle]="{–background: red}" which is not working. Please let me know how will it. Thank you in advance.
i think is is --background? One “-” more than you have
Try this.
<div [ngStyle]="{'background': 'red'}">
</div>
Question is not to use it with div but ion-item. Div works perfectly. Even grid, row too but not ion-item.
Have you tried my answer?
ngStyle not work to ion-item.
Try this.
<ion-item>
Bg Red
</ion-item>
ion-item{
--background: red;
}
OR
<ion-item class="clst">
Bg Red
</ion-item>
.clst{
--background: red;
}
Well, sorry, but as you know, it’s a bug then.
Because NgStyle not work on ion-item not signiticate is a error.
Remember the element of ionic have a custom css class.
this worked for me
[style.--background]="red"