角* ngFor嵌套表单组

时间:2019-06-01 02:07:37

标签: html angular angular-forms

如何在复选框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)
      );
    });
  }

0 个答案:

没有答案