in my ionic project i want to display images with some condition. that is ,i receive a data from API, if it is " Landed" the image want to display with Green color, if “Cancelled” the image want to display with red color.how to possible.
export class StatusPage {
labelColor: string;
status: number;
constructor() {
this.labelColor = "primary";
this.status = 0;
}
applyColor(){
let channel = this.status;
// I just like switching channels
switch(channel) {
case 0: {
this.labelColor = "primary";
break;
}
case 1: {
this.labelColor = "secondary";
break;
}
case 2: {
this.labelColor = "dark";
break;
}
case 3: {
this.labelColor = "light";
break;
}
case 4: {
this.labelColor = "danger";
break;
}
default: {
this.labelColor = "primary";
break;
}
}
}
You would have to apply your own methods of when and why the status changes. I use numbers because I like the idea of switching channels. Each number represents a status. The label, or whatever item you are applying the labelColor string to will change with the status, and you can avoid ngIf’s and hidden’s or whatever, depending on what you actually want to do of course. If you just want to change a color in order to update a status, this is a pretty good template to get you started I think.
I didn’t gather for sure if you were looking to do that, or present different images based on the status.