问题
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