我在表單中添加了多個復選框,并且在將控制元件添加到表單中時,對于某些復選框,我已將禁用屬性值設定為 true。
this.myform.addControl('checkBox1'),
new FormControl({
value: true,
disabled: true,
})
);
this.myform.addControl('checkBox2'),
new FormControl({
value: true,
disabled: false,
})
);
所以兩個復選框都被添加為選中狀態,一個是禁用的,一個是啟用的。現在在使用 this.myform.value 獲取值時,沒有獲取禁用的 checkBox1。只獲得一個復選框,即 checkBox2。
所以請讓我知道在 this.myform.value 中獲取 checkBox1
uj5u.com熱心網友回復:
Angular formGroup.value 不會回傳禁用的控制元件值,而是您可以使用 formGroup.getRawValue() 它將包括您的所有表單控制元件,包括禁用的。
this.myform.value // returns only enabled controls
而是在您的代碼上使用以下代碼來獲取禁用欄位值。
this.myform.getRawValue(); // returns the all form controls value and include disabled controls too
uj5u.com熱心網友回復:
您可以像這樣顯式獲取所需控制元件的值
this.myform.controls.checkBox1.value //disabled checkbox
轉載請註明出處,本文鏈接:https://www.uj5u.com/qiye/510391.html
標籤:有角度的形式禁用控制
上一篇:防止表單輸入值在表單中提交
