title: Angular 2: formGroup expects a FormGroup instance. Please pass one in
body: <p>I am creating a form in Angular 2. My goal is to get data from the API and pass it into the form for editing purposes. However, I am running into this error:</p>
  
  <blockquote>
    <p>EXCEPTION: Uncaught (in promise): Error: Error in ./EditPatientComponent class EditPatientComponent - inline template:1:10 caused by: formGroup expects a FormGroup instance. Please pass one in.</p>
  </blockquote>
  
  <p>Here is the current code with the error.</p>
  
  <p><strong>html</strong></p>
  
  <pre><code>&lt;section class="CreatePatient"&gt;
      &lt;form [formGroup]="patientForm" (ngSubmit)="onSubmit()"&gt;
          &lt;div class="row"&gt;
              &lt;div class="form-group col-12 col-lg-3"&gt;
                  &lt;label for="firstName"&gt;First Name&lt;/label&gt;
                  &lt;input formControlName="firstName" type="text" class="form-control" id="firstName" &gt;
              &lt;/div&gt;
  
          &lt;div class="row"&gt;
              &lt;div class="col-12 col-lg-2"&gt;
                  &lt;button type="submit" name="submit" class="btn btn-block btn-primary"&gt;Save&lt;/button&gt;
              &lt;/div&gt;
          &lt;/div&gt;
      &lt;/form&gt;
  &lt;/section&gt;
  </code></pre>
  
  <p><strong>ts</strong></p>
  
  <pre><code>import { Component, OnInit } from '@angular/core';
  import { ActivatedRoute, Router } from '@angular/router';
  import { FormBuilder, FormGroup, FormControl } from '@angular/forms';
  
  import { PatientService } from './patient.service';
  import { Patient } from './patient';
  
  @Component({
      templateUrl: 'editpatient.component.html'
  })
  export class EditPatientComponent implements OnInit {
      errorMessage: string;
      id: string;
      editMode = true;
      private patientForm: FormGroup;
      private patient: Patient;
  
      constructor(
          private patientService: PatientService,
          private router: Router,
          private activatedRoute: ActivatedRoute,
          private formBuilder: FormBuilder) {
  
          console.log("routes");
          console.log(activatedRoute.snapshot.url[1].path);
      }
  
      ngOnInit() {
          this.getPatient();
      }
  
      getPatient() {
              this.patientService.getPatient(this.activatedRoute.snapshot.url[1].path)
              .subscribe(
                  patient =&gt; {
                      this.id = this.activatedRoute.snapshot.url[1].path;
                      this.patient = patient;
                      this.initForm();
                  },
                  error =&gt;  this.errorMessage = &lt;any&gt;error);
  
      }
  
      onSubmit(form){
          console.log(this.patientForm);
          // Post the API
      };
  
      initForm() {
          let patientFirstName = '';
  
          if (this.editMode) {
              console.log(this.patient.firstName);
              console.log(this.patient.lastName);
              console.log(this.patient.participantUuid);
              patientFirstName = this.patient.firstName;
          }
  
          this.patientForm = new FormGroup({
              'firstName': new FormControl(patientFirstName)
          })
      };
  
  }
  </code></pre>
  
  <p>Any help/pointing me in the right direction would be great! Thanks!</p>