Ionic - Get values from multiple checkboxes in ngFor loop

Hi Guys!

I know this question is pretty stupid but i’m stuck on this for 2/3 days now and i’m still a newbie in ionic 2 :confused:

I have a database that stores player names and a page with checkboxes that lets me select player names.

I would like to put every selected player into an array.

Here is the code:

<ion-item *ngFor="let player of players">
    <ion-label>{{player.name}}</ion-label>
    <ion-checkbox color="dark"></ion-checkbox>
</ion-item>

Is there any way i could achieve that?

I’m having the same dumb problem. Anybody?

My solution for similar problem is for each item to keep a flag that keeps item state (i.e. checked or unchecked). In your case code will look something like this:

<ion-item *ngFor="let player of players">
    <ion-label>{{player.name}}</ion-label>
    <ion-checkbox color="dark" [(ngModel)]="player.checked"></ion-checkbox>
</ion-item>

This way you know what players has been selected and do what ever you need with this information.

Hope it helps.

Hi,
I’d like to parse all checkbox selected values and store them in an array

Players.map(player=>{this.myarray.push…

Tks. It’s work for me…