[英]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.