【问题标题】:Angular ViewChildren can't get changed reactive form valueAngular ViewChildren 无法更改响应式表单值
【发布时间】:2021-01-09 05:39:59
【问题描述】:

我有一个父组件和多个子组件。当我单击父组件中的按钮时,我会获得孩子的有效反应形式值。但是,我只能使用ViewChildren 获得最初修补的表单值。在子组件中,我可以获取整个表单值。

任何提示将不胜感激!谢谢。 这是我的代码:

childcomponent.ts

  this.childForm = this.fb.group({
      DateTime: ['', [Validators.required]],
      Type: ['', [Validators.required]],
      SubType: ['', [Validators.required]],
      CorrectReissueForce: this.fb.group({
       // values will be set using patchvalue, I can only get values here.
        Name: ['', [Validators.required]],
        Mobile: ['', [Validators.required]],
        Address: ['', [Validators.required]],
        // value will be set when filling form.
        SendType: [''],
        IsCancel: ['', [Validators.required]]
      })
    });

parentcomponent.ts

@ViewChildren(childcomponent) child: QueryList<childcomponent>;

saveClick() {
  // can only get Name, Mobile, Address; values of SendType & IsCancel are empty.
  this.child.last.childFormForm.getRawValue()
}

【问题讨论】:

    标签: angular angular-reactive-forms viewchildren


    【解决方案1】:

    在这种情况下,您无需使用 ViewChildren。我认为您可以通过以下方式获得价值:

    this.childForm.get('CorrectReissueForce').value
    

    【讨论】:

      猜你喜欢
      • 2019-09-07
      • 2020-09-23
      • 2022-10-14
      • 2020-08-17
      • 1970-01-01
      • 2020-05-02
      • 2018-10-27
      • 1970-01-01
      • 2020-05-19
      相关资源
      最近更新 更多