【问题标题】:Disabled Rows' Data in Reactive Forms Can't Be Submitted无法提交反应形式的禁用行数据
【发布时间】:2017-12-31 04:52:17
【问题描述】:

我在响应式表单中的行中有这个 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】:

    如果您想包含所有值而不考虑禁用状态,请使用getRawValue 方法而不是value

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

    Stackblitz Example

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 2021-07-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2019-05-25
      • 2021-01-01
      • 1970-01-01
      相关资源
      最近更新 更多