我正在尝试将数据发布到HTTP中,但是我收到formGroup期望的FormGroup实例错误

时间:2018-10-17 09:33:53

标签: angular

  

CreateCollegeComponent.html:4错误错误:formGroup需要一个FormGroup实例。请传递一个。

示例:

<div [formGroup]="myGroup">
  <input formControlName="firstName">
</div>

在您的课堂上:

this.myGroup = new FormGroup({
   firstName: new FormControl()
});
at Function.push../node_modules/@angular/forms/fesm5/forms.js.ReactiveErrors.missingFormException (forms.js:1169)
at FormGroupDirective.push../node_modules/@angular/forms/fesm5/forms.js.FormGroupDirective._checkFormPresent (forms.js:4598)
at FormGroupDirective.push../node_modules/@angular/forms/fesm5/forms.js.FormGroupDirective.ngOnChanges (forms.js:4508)
at checkAndUpdateDirectiveInline (core.js:9239)
at checkAndUpdateNodeInline (core.js:10507)
at checkAndUpdateNode (core.js:10469)

1 个答案:

答案 0 :(得分:0)

当我在ngOnInit中定义表单时,我遇到了同样的问题。将其移至构造函数,问题便得到解决。