我在响应形式的行内部有这个unit_price,它需要被提交,并且还需要被禁用,因为它已经设置好了。为什么我提交后无法在console.log中看到“unit_price”?我怎样才能解决这个问题?这里是代码CODE LINK的链接
initGroup() {
let rows = this.addForm.get('rows') as FormArray;
rows.push(this.fb.group({
ingredient_id: ['', Validators.required],
unit_price: new FormControl({ value: '', disabled: true }, Validators.required),
}))
}
如果您想要包括所有值而不管禁用状态,请使用getRawValue
方法而不是value
const Data = {
ingredients: (this.addForm.get('rows') as FormArray).getRawValue(),
}