Ich habe ein reaktives 2-Form-Formular mit einer Liste von Kontrollkästchen, die Daten gebunden sind. Das funktioniert gut, aber jetzt muss ich eine Schaltfläche hinzufügen, um alle Kontrollkästchen zu aktivieren.Aktivieren Sie alle Kontrollkästchen in einem FormArray - Angular 2 Reactive Form
Heres, wie mein FormGroup konfiguriert ist:
private buildForm() {
this.groupForm = this._formBuilder.group({
bookId: this._formBuilder.control(null),
startDate: this._formBuilder.control(null),
groupTotal: this._formBuilder.control(null),
chapterGrouping: this._formBuilder.control("all"),
groupChapters: this.buildChapters()
});
}
private buildChapters() {
const chapters = this.chapters.map(chapter => {
return this._formBuilder.control(chapter.selected)
});
return this._formBuilder.array(chapters);
}
Heres mein HTML:
<div class="form-group">
<label for="">Select chapters</label>
<div *ngFor="let chapter of formChapters.controls; let i=index" class="checkbox">
<label>
<input type="checkbox" [formControl]="chapter" >
{{chapters[i].title}}
</label>
</div>
</div>
Wie würde ich die FormArray Zugriff auf alle Kontrollkästchen setzen, wie überprüft?
perfekt funktioniert! Vielen Dank. Ich schätze die Erklärung. – sykespro