簡體   English   中英

Angular ViewChildren 無法獲取更改的反應形式值

[英]Angular ViewChildren can't get changed reactive form value

我有一個父組件和多個子組件。 當我單擊父組件中的按鈕時,我會獲得孩子的有效反應形式值。 但是,我只能使用ViewChildren獲得最初修補的表單值。 在子組件中,我可以獲得整個表單值。

任何提示將不勝感激。 謝謝:這是我的代碼:

子組件.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]]
      })
    });

父組件.ts

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

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

在這種情況下,您無需使用 ViewChildren。 我認為您可以通過以下方式獲得價值:

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

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM