无法提交已禁用的反射形式的行数据

问题描述 投票:0回答:1

我在响应形式的行内部有这个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),
    }))
  }
angular angular-reactive-forms angular4-forms
1个回答
0
投票

如果您想要包括所有值而不管禁用状态,请使用getRawValue方法而不是value

const Data = {
  ingredients: (this.addForm.get('rows') as FormArray).getRawValue(),
}

Stackblitz Example

© www.soinside.com 2019 - 2024. All rights reserved.