I Angular 2 reaktive Form Builder wie diese bin mit:Angular2 Form Builder, speichern Array von Werten
<div class="questionSection">
<b class="questionTitle">Remove records that don't have:</b>
<div class="horizontalOptions">
<label
class="horizontalOption"
*ngFor="let choice of excludeRecords"
>
<input type="checkbox"
[value]="choice.value"
formControlName="excludedRecords"
>
{{choice.label}}
</label>
</div>
</div>
Ich möchte die excludedRecords
Wert ein Array sein, das ist die Variable, die den HTML-Code der Erzeugung:
excludeRecords = [
{label: 'Full Mailing Address', value:'fullMailing', checked:false},
{label: 'Full Office Address', value:'fullOffice', checked:false},
{label: 'Email Address', value:'emailAddress', checked:false},
{label: 'Phone #', value:'phoneNum', checked: false},
];
Und das ist, wie ich die ursprüngliche Form Auswahlen bin Erzeugung:
constructor(private formBuilder: FormBuilder) {
this.initialValues = {
mainChoice: 'entireUSA',
excludedRecords: [],
stateChoice: 'all',
includedStates: [],
specialtyChoice: 'all',
includedSpecialties: []
}
this.form = formBuilder.group(this.initialValues);
this.formSelections = this.initialValues;
this.form.valueChanges.subscribe(
data => {
console.log('form changed', data);
this.formSelections = data;
}
);
}
Rechts Jetzt wird nur der Wert auf "True" oder "False" gesetzt, aber ich möchte, dass alle Checkbox-Eingaben ein Array von Werten ausgeben. Ist dies mit Angular2 Form Builder möglich?