带有反应形式的Angular 2 Checkbox值 [英] Angular 2 Checkbox value with Reactive form
本文介绍了带有反应形式的Angular 2 Checkbox值的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我有2个反应形式的复选框,我需要在POST api中传递这些复选框的值,现在它们将在状态传递值. 下面是复选框代码,它仅传递了诸如true或false之类的状态,而不是诸如1,2之类的值.
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"> {{CatArry[i].cat_name}}
</div>
</div>
推荐答案
模板端:
<input type="checkbox" formControlName="servicelatest" [value]="CatArry[i].id"
(change)="services[$event.target.getAttribute('value')]=$event.target.checked"/>
组件侧:
services = {};
然后将服务用作您所选的复选框值
And then use services as your selected checkboxes values
这篇关于带有反应形式的Angular 2 Checkbox值的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文