0

I have a reactive form within Angular 4+ where I have multiple check boxes like so:

enter image description here

Now a user can select as many of the checkboxes as possible. So that the output of this form is an array of selected check boxes like so:

[
  "I have a bike",
  "I have a nothing",
  "I have a test"
]

I have no idea how to handle this in reactive forms. Please note I'm using the following:

import {FormGroup, FormBuilder, Validators} from "@angular/forms";

What I want:

How can I push checked values within a reactive form array before I send it to the DB.

How can this be achieved in reactive forms?

2
  • so you want a console log from reactive form after submitting? Commented Jan 6, 2018 at 13:08
  • @Lakindu no. After submitting the data gets pushed to the server to be saved in DB. I don't know how to add checked values within a reactive form so it looks like the output in my question. Does this make sense? Commented Jan 6, 2018 at 13:11

1 Answer 1

0

create an empty array.then in the submit function run through all the controls of the form and get their values with the help of 'get(controlName)' and push these values into array. the resulting array can be submitted as usual.

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

Comments

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.