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-checkbox color="dark"></ion-checkbox>

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-checkbox color="dark" [(ngModel)]="player.checked"></ion-checkbox>

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

Hope it helps.


I’d like to parse all checkbox selected values and store them in an array>{this.myarray.push…

Tks. It’s work for me…