Angular2:在FormGroup.value中找不到禁用的窗体控件的值 [英] Angular2: Disabled Form Control's values not found in FormGroup.value

查看:49
本文介绍了Angular2:在FormGroup.value中找不到禁用的窗体控件的值的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有:

this.editMemberForm = this.formBuilder.group({
  name: [{value: '', disabled: true}],
  id: [{value: '', disabled: true}],
  relType: ''
});

然后我将值设置为禁用的表单控件:

Then I set values to the disabled form controls:

this.editMemberForm.patchValue({
  name: 'Me',
  id: '000',
});

onSubmit()中:

console.log('Saving data', this.editMemberForm.value);
// { relType: '123' }

我需要this.editMemberForm.value成为{ name: "Me", id: '000', relType: "123" }.

推荐答案

您可以使用

You can use getRawValue() to get disabled controls values back as well.

这篇关于Angular2:在FormGroup.value中找不到禁用的窗体控件的值的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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