问题描述
我有一个父组件和多个子组件。单击父组件中的按钮时,我将获得孩子的有效反应形式值。但是,我只能使用ViewChildren
获得最初打补丁的表单值。在子组件中,我可以获得完整的表单值。
childcomponent.ts
this.childForm = this.fb.group({
DateTime: ['',[Validators.required]],Type: ['',SubType: ['',CorrectReissueForce: this.fb.group({
// values will be set using patchvalue,I can only get values here.
Name: ['',Mobile: ['',Address: ['',// 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()
}
解决方法
在这种情况下,您无需使用ViewChildren。我认为您可以通过以下方式获得价值:
this.childForm.get('CorrectReissueForce').value