【发布时间】:2021-01-09 05:39:59
【问题描述】:
我有一个父组件和多个子组件。当我单击父组件中的按钮时,我会获得孩子的有效反应形式值。但是,我只能使用ViewChildren 获得最初修补的表单值。在子组件中,我可以获取整个表单值。
任何提示将不胜感激!谢谢。 这是我的代码:
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()
}
【问题讨论】:
标签: angular angular-reactive-forms viewchildren