使用Angular中的反应形式动态添加基于条件的行

问题描述 投票:1回答:1

是否有可能我能够根据角度反应形式中的某些条件添加行?如果有,请帮我做。我已经在stackblitz中启动了它。请检查此链接https://stackblitz.com/edit/dynamically-add-rows

this.addForm.get("items").valueChanges.subscribe(val => {
      console.log(val);
      if (val === true) {
        this.addForm.get("items_value").setValue("yes");

        // How to add row here?
        this.addForm.addControl(rows, 'rows')
      }
      if (val === false) {
        this.addForm.get("items_value").setValue("no");

        // How to remove row here?
        this.addForm.removeControl(rows, 'rows')
      }
    });
angular angular6 angular-reactive-forms angular-forms angular4-forms
1个回答
© www.soinside.com 2019 - 2024. All rights reserved.