我有一个父组件和多个子组件。当我单击父组件中的按钮时,我会获得孩子的有效反应形式值。但是,我只能使用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()
}