You can use the ternary operator to set the color in that way:
[color]="chat.status === 'A' ? 'danger' : 'success'"
I'm using Ionic's danger
as the red color, and Ionic's success
color as the green color but you can add your own colors if you want.
Another option could be to add a class to the ion-icon
element and set the color using CSS (like explained in https://ionicons.com/usage):
<ion-icon
slot ="end"
name="ellipse-outline"
[class.red]="chat.status === 'A'"
[class.green]="chat.status === 'B'"
></ion-icon>
And then in your scss file:
ion-icon.red {
color: red; // your red color
}
ion-icon.green {
color: green; // your green color
}
与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…