如何在 Angular2 中使禁用的反应式表单可编辑 [英] How to make a disabled reactive form Editable in Angular2

查看:31
本文介绍了如何在 Angular2 中使禁用的反应式表单可编辑的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在使用下面的代码创建一个表单并将其设为只读,我是 angular 的新手

I am Using below code to create a form and make it readOnly, I am new to angular

createForm() {
        this.comapnyIdentificationForm = this.fb.group({
          businessName: ['', Validators.required ],
          adressPrimary: '',
          adressSecondary: '',
          city:'',
          state: '',
          zipCode: '',
          country: '',
          companyPhone: '',
          DUNS: ''
        });
         this.comapnyIdentificationForm.disable();
      }

我需要启用它并将编辑后的数据发布回 Json :

I need to make it enabled and post edited data back to Json :

<button type="button"  (click)="EditData()" class="btn modal-btn btn-default">Edit</button>

推荐答案

只需使用以下代码即可启用您的表单.

Just use following code to enable your form .

this.comapnyIdentificationForm.enable();

获取一个json对象.使用以下代码:

To get a json object. Use following code:

this.comapnyIdentificationForm.value;

要使用后端数据填写表单,请使用以下代码:this.comapnyIdentificationForm.patchValue(jsonData);

To fill-up your form with backend data use following code: this.comapnyIdentificationForm.patchValue(jsonData);

这篇关于如何在 Angular2 中使禁用的反应式表单可编辑的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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