1

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 Answer 1

1

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

Sign up to request clarification or add additional context in comments.

10 Comments

Thanks for replay but still not getting proper thing. After post i have still get true and false. i have put same code in html which you put and in component i have take a variable which type is any but problem still remain
do i need to put services in reactive form group value?
Will you please share your code , by your code I can expect you have put it in loop
Hi i have share my loop code please have look on this if anything you want let me known
services = {}; try with this.
|

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.