Angular 2 Checkbox value with Reactive form

2019-09-15 03:22发布

i have checkbox in angular 2 reactive form i need to pass the values of these checkbox in POST api , Right now they will pass value on status. below are checkbox code it only passed the status like true or false instead of value like 1,2 something like that.

<input type="checkbox" formControlName="servicelatest"  [value]="CatArry[i].id" (change)="serviceCheckBox($event)"/>

-------------------**------------------------

<div *ngFor="let serviceType of laceDetailFrom.controls.serviceType.controls; let i=index" >
<div  [formGroupName]="i">

<input type="checkbox" formControlName="servicelatest"  [value]="CatArry[i].id" (change)="services[$event.target.getAttribute('value')]=$event.target.checked">&nbsp;{{CatArry[i].cat_name}}
                             </div>
                           </div>

1条回答
趁早两清
2楼-- · 2019-09-15 03:38

Template Side :

<input type="checkbox" formControlName="servicelatest"  [value]="CatArry[i].id" 
(change)="services[$event.target.getAttribute('value')]=$event.target.checked"/>

Component Side :

services = {};

And then use services as your selected checkboxes values

查看更多
登录 后发表回答