Reputation: 355
I don't know how to retreive the values from a list of toggles. Each toggle represents if a student was in class or not.
There is a submit button below which when pressed, will send those students with a 'false' value on the toggle into a database.
I don't know how to get this information, it seems tricky using Ionic Angular.
I've tried adding an if function to my function on the .ts file, but it doesn't like the 'value' I added.
<ion-list>
<ion-item *ngFor="let student of students; let i = index">
<ion-label>{{ student.nom }}</ion-label>
<ion-toggle (ionChange)="onChange($event, i)">
</ion-toggle>
</ion-item>
<ion-button (click)="signalAbsence($event, i)">
Confirmer
</ion-button>
</ion-list>
onChange(event, i) {
if (event.target.checked) {
// this.buttonOn(event, i);
this.students.value = true;
console.log(this.students.value, i);
}
else {
// this.buttonOff(event, i)
this.students.value = false;
console.log(this.students.value, i);
}
}
signalAbsence(event, i) {
event.preventDefault();
// loop through students to find which have false value, add to array ??
if (this.students[i].value === false) {
const date = this.students[0].date;
const time = this.students[0].time;
const cours = this.students[0].cours;
const lieux = this.students[0].lieux;
const etudiant_nom = this.students[0].nom;
const etudiant_id = this.students[0].id;
const url = window.location.href;
const id = url.substring(url.lastIndexOf('/') + 1);
this.Auth.updateAbsenceDb(date, time, cours, lieux, id, etudiant_nom,
etudiant_id);
alert("Mis à jour effectué");
this.router.navigate(['cours/', id]);
} else {
const url = window.location.href;
const id = url.substring(url.lastIndexOf('/') + 1);
alert("Mis à jour effectué");
this.router.navigate(['cours/', id]);
}
}
So I need to know which students have a false value, and then how to use that info and send it to a database using the signalAbsence funtion at the bottom of this code.
Upvotes: 0
Views: 213
Reputation: 355
Finally, I altered the this.students part in the toggle function, to be... this.students[i].value = true;
This gave each row the value and not the collection of rows in the array.
Thanks for your input.
Upvotes: 0
Reputation: 9
There is another easier way. In the signalAbsence(event,i), you could add ann array and push the true value in this array and push false ones in another array and after that you push what you want from these to to your database.
Upvotes: 1