typescript - How to grab ID from multiple selected checkbox's on submit? Ionic 2+ / Angular 2+ -




i'm having trouble getting id of checked item on submit. i'm able retrieve selected id on change not on submit. note - data i'm getting not have checked value. there might way push selected value data structure unsure how so.

html

<form [formgroup]="itemform" (ngsubmit)="submit(itemform)">     <ion-list >       <div>       <ion-item>         <ion-checkbox formcontrolname="selectall" (click)="checkall()" [(ngmodel)]="selectedall" ></ion-checkbox>       </ion-item>       <ion-item *ngfor="let item of items">         <ion-label>         {{item.text}}         </ion-label>         <ion-checkbox [checked]="selectedall" formcontrolname="recvd" value="item.id" (ionchange)="select(item)"></ion-checkbox>     </ion-item>        </div>         <button ion-button full type="submit"></button>     </ion-list>   </form> 

ts

export class messagespage { selectedall: boolean = false;  items: [];  constructor(){}  submit(form){    console.log(form.value, 'formvalue here') // returns true  }  select(item){    console.log(item) //this returns selected item on change id }  } 

i don't know why used both formcontrolname , ngmodel? can using ngmodel shown below.you need have boolean property checked on items array.

    <ion-item *ngfor="let item of items">         <ion-label>         {{item.text}}         </ion-label>        <ion-checkbox checked="false" [(ngmodel)]="item.checked" (ionchange)="select(item)"></ion-checkbox>     </ion-item> 




wiki

Comments

Popular posts from this blog

Asterisk AGI Python Script to Dialplan does not work -

python - Read npy file directly from S3 StreamingBody -

kotlin - Out-projected type in generic interface prohibits the use of metod with generic parameter -