formGroup expects a FormGroup instance error in Angular2 form

Aakash Thakur picture Aakash Thakur · Feb 8, 2017 · Viewed 9.2k times · Source

I am trying to create a basic form in Angular 2 on plunker but faced with the below error on Chrome Dev's Console:

VM8247:27 EXCEPTION: Error in ./App class App - inline template:1:12 caused by: formGroup expects a FormGroup instance. Please pass one in.

       Example:


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

    In your class:

    this.myGroup = new FormGroup({
       firstName: new FormControl()
    });

Plus there are some other errors also which point to more or less the above error only. I came across other answers on SO related to this but most of them had typos in their code.

Please have a look at the plunker .

Answer

smnbbrv picture smnbbrv · Feb 8, 2017

You actually have a typo in your plunker...

Instead of

constructor(fb:FormBuilder){

You write

cosntructor(fb:FormBuilder){

That is why your form isn't getting initialized and remains undefined for Angular.