I need help with capturing the values of checked checkboxes and storing them in a string to use in my API. I want to retrieve the value if a checkbox is unchecked.
<div *ngFor="let x of groupesTable">
<input type="checkbox" [(ngModel)]="group" (change)="">
{{x.nom_groupe | uppercase}}
</div>
I am unsure of the method or approach I should take in TypeScript to achieve this. Any guidance would be greatly appreciated.
This is an updated version
<div class="form-check" *ngFor="let x of groupesTable">
<label class="form-check-label" for="check1">
<input type="checkbox" class="form-check-input" nom="check1" [value]= "x.nom_groupe"
name="x.nom_groupe" (change)="callMe($event, x.nom_groupe)" [(ngModel)]="grp">{{x.nom_groupe | uppercase}}
</label>
</div>
In the .ts file, I have implemented this function:
callMe(event, nom) {
if (event.target.checked)
{
console.log(nom);
this.nomgrps=this.nomgrps+nom.toUpperCase()+" ";
console.log(this.nomgrps);
}
else {
console.log(this.nomgrps);
}}
However, it seems like the functionality is not working as expected. Please assist me in troubleshooting why all checkboxes are getting checked when only one is selected.