Hi everyone!
I am new to this forum, first time posting, so I apologize if they way of writing this isn’t proper.
I am trying to create a list of cards, and each card comes from an array of subjects, based on a course, day and the hour you choose. There are cases where there is only 1 subject, but the could be more than one.
Then each card has three buttons, great, good and bad, and depending on which button you choose, the background of the card-header changes to one color or another; blue, green and red in this case and order.
I save each subject and it’s color properly, but when there are more than one cards, it automatically shows the same color for all of them, even knowing each of them has different colors.
I bet this is an issue related to ngClass, and I would like someone to help me if could be possible, thanks in regard!
This is my code for html:
<ion-list *ngIf="horaSeleccionada">
<ion-item-sliding>
<ion-item *ngFor="let asignatura of asignaturas">
<ion-card>
<ion-card-header [ngClass]="showColor()">
<ion-card-title text-center>
{{asignatura}}
</ion-card-title>
</ion-card-header>
<ion-row style="height: 8px"></ion-row>
<ion-card-content align-items-center>
<button *ngFor="let valoracion of listaValoraciones" clear ion-button color="{{valoracion.color}}"
(click)="cambiarValoracion(asignatura, valoracion.nombre)" icon-start>
<ion-icon name="{{valoracion.icono}}"></ion-icon>
{{valoracion.nombre}}
</button>
</ion-card-content>
</ion-card>
</ion-item>
</ion-item-sliding>
</ion-list>
I have saved an array of Asignaturas(Subjects), which includes name and value of each subject. Then using showColor and cambiarValoracion, I compare the string result of {{asignatura}} with the name of each array item, and once I have found it I change its color.
This way I am able to save each subject with it’s color, but again if there are more than one cards they show all the same color. If I chose a day and an hour where there is only one the color is proper.
These are my methods showColor() and cambiarValoracion();
showColor() {
if (this.asignaturaSeleccionada.valoracion === "") {
return 'blanco';
}
if (this.asignaturaSeleccionada.valoracion === "Estupenda") {
return 'azul';
}
if (this.asignaturaSeleccionada.valoracion === "Pasable") {
return 'verde';
}
if (this.asignaturaSeleccionada.valoracion === "Horrorosa") {
return 'rojo';
}
}
cambiarValoracion(asignatura, valoracion) {
this.asignatura2 = asignatura;
for (let i = 0; i < this.listaAsignaturas.length; i++) {
if (this.asignatura2.match(this.listaAsignaturas[i].nombre)) {
this.asignaturaSeleccionada = this.listaAsignaturas[i];
this.asignaturaSeleccionada.valoracion = valoracion;
}
}
console.log(this.asignaturaSeleccionada);
this.showColor();
}