I am trying to get a simple example of work using reactive / model forms. I want to bind an array of flags to a list of values, not a list of boolean values.
This plunker shows the problem: http://plnkr.co/edit/a9OdMAq2YIwQFo7gixbj?p=preview The values associated with the forms are logical, I would like the answer to be something like ["value1", "value2", etc]
I have something like this, but I don’t know how to get the result I want?
Template:
<form [formGroup]="checkboxGroup"> <input *ngFor="let control of checkboxGroup.controls['myValues'].controls" type="checkbox" id="checkbox-1" value="value-1" [formControl]="control" /> </form>
And component:
let checkboxArray = new FormArray([ new FormControl({checked: true, value: "value1"}), new FormControl({checked: false, value: "value2"}))]); this.checkboxGroup = _fb.group({ myValues: checkboxArray });
source share