如何使用angular8从一行中编辑新添加的项目 [英] How to edit the newly added item from a row using angular8

查看:37
本文介绍了如何使用angular8从一行中编辑新添加的项目的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在使用反应形式,如果我编辑数据库中已经存在的值,它将被编辑并保存在该特定行中,因为它具有作为agentw9id的唯一ID,但是如果我创建新项目并对其进行编辑,它将被添加了新的ID,因此我尝试使用此方法,在这里,对于索引0,它不起作用,但是对于其他值,它用于获取更新,但是它用于在最终保存时使用所​​有值,而不是发送已编辑的值更改新添加的项目.

i am using reactive forms, if i edit the values which is already present in database it gets edited and gets saved in that particular row, as it has unique id as agentw9id, but if i create new item and edit that, it gets added with the new id, so i tried with this method, here, for index 0, it doesnt work but for other values it used to get update, but it used to go all values at time of final save instead of sending the edited change of the newly added items.

演示:演示

TS:

saveW9Details(item) {
this.addButtonDisable = false;
        if(this.employee ) {
          if(item.agentW9id.value) {
            for(var i=0;i<this.employee.length;i++){
              if(this.employee[i].agentW9id===item.agentW9id.value){
                this.employee[i].taxId=item.taxId.value;
                this.employee[i].businessType=item.businessType.value;
                this.employee[i].signatureDate=item.signatureDate.value;
                this.employee[i].agentW9id = item.agentW9id.value;
                // updated=true;
                this.temporaryControls.push(this.employee[i]);
                this.getFormData.removeAt(i)
              }
           }
          } else {

            var temp={
              taxId:item.taxId.value,
              signatureDate:item.signatureDate.value,
              businessType: item.businessType.value,
              agentW9id:item.agentW9id.value,
             originalFileName:item.fileName.value?item.fileName.value.slice(12):''
            }
            if(this.employee) {
              this.employee.push(temp);
              this.temporaryControls.push(temp)
            } 
      //  this.getFormData.removeAt(item)
          }
        } else {
         console.log(item,"dsds")

            let temp={
              taxId:item.taxId.value,
              signatureDate:item.signatureDate.value,
              businessType: item.businessType.value,
              agentW9id:item.agentW9id.value,
              businessName: item.businessName[0].value,
             originalFileName:item.fileName.value?item.fileName.value.slice(12):''
            };
            this.temporaryControls.push(temp)
        }

       this.getFormData.removeAt(item);


        }

}

推荐答案

我建议在实际的FormArray上循环.这样,您将掌握每个控件.然后您可以将此控件传递给编辑功能.这样,您就不必担心索引.

I would recommend looping on actual FormArray. This way you will get hold of each control. and then you can pass this control to edit function. This way you dont need to worry about index.

这篇关于如何使用angular8从一行中编辑新添加的项目的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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