简体   繁体   中英

Angular ViewChildren can't get changed reactive form value

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

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

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

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM