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?

Skywalker
  • 4,984
  • 16
  • 57
  • 122
  • so you want a console log from reactive form after submitting? – Lakindu Gunasekara Jan 06 '18 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? – Skywalker Jan 06 '18 at 13:11

1 Answers1

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.