jeudi 1 décembre 2016

Angular 2 reactive forms: array of checkbox values

Given a list of checkboxes bound to the same formControlName, how can I produce an array of checkbox values bound to the formControl, rather than simply true/false?

Currently:

<form [formGroup]="checkboxGroup">
    <input type="checkbox" id="checkbox-1" value="value-1" formControlName="myValues" />
    <input type="checkbox" id="checkbox-2" value="value-2" formControlName="myValues" />
    <input type="checkbox" id="checkbox-3" value="value-2" formControlName="myValues" />
</form>

checkboxGroup.controls['myValues'].value will produce:

true or false

When I want it to produce:

['value-1', 'value-2', ...]




Aucun commentaire:

Enregistrer un commentaire