Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

formGroup expects a FormGroup instance

I have an Angular 2 RC4 basic form example on Plunkr that appears to throw the following error (In Chrome DEV console)

Here's the plunkr

https://plnkr.co/edit/GtPDxw?p=preview

Error:

browser_adapter.ts:82 EXCEPTION: Error: Uncaught (in promise): EXCEPTION: Error in ./App class App - inline template:1:7 ORIGINAL EXCEPTION: formGroup expects a FormGroup instance. Please pass one in.            Example: <form [formGroup]="myFormGroup">  ORIGINAL STACKTRACE: Error: formGroup expects a FormGroup instance. Please pass one in.            Example: <form [formGroup]="myFormGroup">      at new BaseException (https://npmcdn.com/@angular/[email protected]/src/facade/exceptions.js:27:23)     at FormGroupDirective._checkFormPresent (https://npmcdn.com/@angular/[email protected]/src/directives/reactive_directives/form_group_directive.js:110:19)     at FormGroupDirective.ngOnChanges (https://npmcdn.com/@angular/[email protected]/src/directives/reactive_directives/form_group_directive.js:39:14)     at DebugAppView._View_App0.detectChangesInter 
like image 272
user6123723 Avatar asked Jul 18 '16 19:07

user6123723


1 Answers

There are a few issues in your code

  • <div [formGroup]="form"> outside of a <form> tag
  • <form [formGroup]="form"> but the name of the property containing the FormGroup is loginForm therefore it should be <form [formGroup]="loginForm">
  • [formControlName]="dob" which passes the value of the property dob which doesn't exist. What you need is to pass the string dob like [formControlName]="'dob'" or simpler formControlName="dob"

Plunker example

like image 96
Günter Zöchbauer Avatar answered Sep 21 '22 21:09

Günter Zöchbauer