[英]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
.但是,我只能使用
ViewChildren
获得最初修补的表单值。 In child component, I can get whole form values.在子组件中,我可以获得整个表单值。
Any hint would be appreciated.任何提示将不胜感激。 thank you: Here's my code:
谢谢:这是我的代码:
childcomponent.ts子组件.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父组件.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.在这种情况下,您无需使用 ViewChildren。 I think you can get value by:
我认为您可以通过以下方式获得价值:
this.childForm.get('CorrectReissueForce').value
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.