Angular ViewChildren can't get changed reactive form value

515 views Asked by At

I have one parent component and multiple children components. I'd to get children's valid reactive form value when I click a button in parent component. However, I can only get originally patched form value with ViewChildren. In child component, I can get whole form values.

Any hint would be appreciated! thank you. Here's my code:

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()
}

1

There are 1 answers

0
V.Tur On

You no need use ViewChildren in this case. I think you can get value by:

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