Checkbox ngModel from Array

Hi, is it possible to bind an ngModel array to a list of checkbox

// in controller
this.myDataArray = [ 2 ];
this.myEntries = [
    { id: 1, name: 'Item 1' },
    { id: 2, name: 'Item 3' },
    { id: 3, name: 'Item 2' },

// in template
    <button ion-item
    *ngFor="let option of myEntries;" >
        <ion-label>{{ }}</ion-label>
        <ion-checkbox item-right  [(ngModel)]="myDataArray" value="{{ }}"></ion-checkbox>

// result
- Item 1 [ ]
- Item 2 [x]
- Item 1 [ ]

So each time one is checked, it’s added to myDataArray, and removed if unchecked.

I’m wondering the same thing… Find any answers?


The proposed syntax in the OP makes no sense, because it is binding multiple checkboxes to the same property. If possible, I would build this array at form submission time instead of constantly updating it as checkboxes are checked and unchecked, but either way this is something you are going to have to do in controller code.