使用Angular中的反应形式根据条件动态添加行 [英] Dynamically Add Rows Based on Condition Using Reactive Forms in Angular

查看:78
本文介绍了使用Angular中的反应形式根据条件动态添加行的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我是否有可能能够基于Angular反应形式的某些条件添加行?如果是,请帮助我.我已经在我的堆叠闪电战中开始了它.请检查此链接 https://stackblitz.com/edit/dynamically-add-rows

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')
      }
    });

推荐答案

这是编辑过的stackblitz:

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

这篇关于使用Angular中的反应形式根据条件动态添加行的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆