如何从表单组中禁用的表单控件获取值? [英] How to get values from disabled form controls in a form group?
本文介绍了如何从表单组中禁用的表单控件获取值?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我尝试使用表单状态对象初始化新的FormControl,但我发现该控件不会影响表单验证,并且也会从FormGroup值中消失.
I tried to initialize my new FormControl using form state object and I noticed then this control doesn't influence my form validation and it also disappear from FormGroup values.
this.userForm = new FormGroup({
email: new FormControl('', Validators.required),
firstName: new FormControl('',Validators.required),
lastName: new FormControl('',Validators.required),
role: new FormControl({value: 'MyValues', disabled: true},Validators.required),
})
现在,如果我尝试这样做:
Now if I try to do:
this.userForm.value //email, firstName, lastName
有人遇到过这个问题吗?有什么办法吗? 角度版本:5.2.6
Have someone encountered this issue ? Any solution ? Angular version: 5.2.6
推荐答案
这不是问题,是预期的行为.如果您想包括所有值,而不论其禁用状态如何,请使用以下命令:
This is not an issue, is the expected behavior. If you'd like to include all values regardless of disabled status, use the following:
this.userForm.getRawValue()
这篇关于如何从表单组中禁用的表单控件获取值?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文