sách gpt4 ăn đã đi

angular - 如何禁用表单控件但保持值(value)

In lại 作者:太空狗 更新时间:2023-10-29 16:52:25 26 4
mua khóa gpt4 giày nike

我有一个 react 形式。在编辑时我想禁用一个控件。

以下作品:

   this.myForm.controls['analysis_horizon'].disable();

但是,关键 analysis_horizon 不再在我的 myForm.value 散列中。

如何禁用具有反应式表单的字段但将值保留在表单值哈希中?

我试过 [disabled]= 但我得到以下信息:

It looks like you're using the disabled attribute with a reactive form directive. If you set disabled to true
when you set up this control in your component class, the disabled attribute will actually be set in the DOM for
you. We recommend using this approach to avoid 'changed after checked' errors.

Ví dụ:
form = new FormGroup({
first: new FormControl({value: 'Nancy', disabled: true}, Validators.required),
last: new FormControl('Drew', Validators.required)
});

我在编辑时将数据库中的数据加载到表单控件中,但我需要一个字段不允许更改。

câu trả lời hay nhất

Bạn có thể sử dụng getRawValue() 代替 giá trị 属性。根据tài liệu :

The aggregate value of the FormGroup, including any disabled controls.

If you'd like to include all values regardless of disabled status, use this method. Otherwise, the giá trị property is the best way to get the value of the group.

this.myForm.getRawValue()

关于angular - 如何禁用表单控件但保持值(value),我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/42180696/

26 4 0
Chứng chỉ ICP Bắc Kinh số 000000
Hợp tác quảng cáo: 1813099741@qq.com 6ren.com
Xem sitemap của VNExpress