Dynamically Add Rows Based on Condition Using Reactive Forms in Angular

拟墨画扇 提交于 2021-01-28 08:00:51

问题


Is it possible that i will be able to add rows based on certain condition in Angular reactive forms? If yes, please help me do it. I've already started it in my stackblitz. Please check this link 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')
      }
    });

回答1:


here is the edited stackblitz :https://stackblitz.com/edit/dynamically-add-rows-gk4veg?file=app%2Fapp.component.html



来源:https://stackoverflow.com/questions/52241765/dynamically-add-rows-based-on-condition-using-reactive-forms-in-angular

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!