form.valueChanges不会为禁用的控件发出值 [英] form.valueChanges doesn't emit values for disabled controls

查看:54
本文介绍了form.valueChanges不会为禁用的控件发出值的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一个Angular反应形式.我订阅它的值更改,并将更改发送到父组件.用户可能会禁用某些控件.问题是当发出表单valueChanges时,缺少来自禁用控件的值.我已经设置了一个基本的示例.

I have an Angular Reactive form. I subscribe to its value changes and will emit changes to parent component. Some of the controls might get disabled by the user. The problem is that values from disabled controls are missing when form valueChanges are emitted. I've set a basic example.

如果选中此复选框并且禁用了电子邮件输入,则不会记录任何表单控件值.但我想获取所有表单值.

When the checkbox is checked and the email input is disabled, there is no form control value logged. But I'd like to get ALL form values.

推荐答案

使用FormGroup的getRawValue()来包含控制值,而不考虑启用/禁用状态.

Use the FormGroup's getRawValue() to include control values regardless of enable/disable state.

API文档中的更多信息

this.myForm.valueChanges.subscribe(() => {
    this.formValues =  JSON.stringify(this.myForm.getRawValue());
});

这是分叉的示例

这篇关于form.valueChanges不会为禁用的控件发出值的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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