类似于https://stackoverflow.com/questions/52235952/cannot-read-property-of-undefined-reactive-forms
StackBlitz-https://stackblitz.com/edit/github-rbjwcd-wtrevw
上述演示存在问题。我正在尝试使表单生成器按照示例与模型一起使用。问题出在.group
属性上。
contactForm: FormGroup;
createFormGroupWithBuilderAndModel(formBuilder: FormBuilder) {
return this.formBuilder.group({
personalData: formBuilder.group(new PersonalData()),
requestType: '',
text: ''
});
}
我认为问题可能不是在返回时初始化表格:
this.contactForm = this.formBuilder.group
有人可以让它运行吗?
答案 0 :(得分:2)
修复您的堆叠闪电战...
constructor(private formBuilder: FormBuilder) {
this.contactForm = this.createFormGroupWithBuilderAndModel(formBuilder);
}