如何在复选框formgroup上执行* ngFor以及在HTML模板中访问此嵌套formgroup的正确方法是什么?
this.postForm = this.fb.group({
osnovne: this.fb.group({
sekcija: ["market", Validators.required],
kategorija: "",
cena: [""],
dogovor: false,
opis: ""
}),
detaljne: this.fb.group({
select: this.fb.group({
name: ""
}),
checkboxes: this.fb.group([])
}),
imagePath: this.fb.group({
data: ""
})
});
data = [
{ id: false, name: "Levo" },
{ id: false, name: "Desno" },
{ id: false, name: "Ovo" },
{ id: false, name: "Ono" }
];
从数据库动态添加表单组...
addCheckboxes() {
this.data.forEach(element => {
this.postForm.controls.detaljne.controls.checkboxes.addControl(
element.name,
new FormControl(false)
);
});
}