0

I'm creating an app using Ionic and I've created a page survey which is SurveyPage. Inside of this page, I've got some texts and a component which is <app-survey-view> which is SurveyViewComponent

Inside SurveyViewComponent, I set a form and I have this error on [formGroup]="surveyForm" inside my HTML :

Can't bind to 'formGroup' since it isn't a known property of 'form'

My property surveyForm has been well set and it should be working.

I tried to import ReactiveFormsModule inside my app.module.ts but it isn't working.

Even inside my SurveyPageModule I tried to import and export the ReactiveFormsModule but nothing changed.

Can someone help me fixing this ?

Thanks

EDIT : After some research, it seems like my page which has a module.ts doesn't let its child inherit the ReactiveFormsModule. I mean, survey-view, can't access ReactiveFormsModule which has been declared in its parent's module (SurveyPage)

2 Answers2

0

Add FormsModule and ReactiveFormsModule into the imports section of the module you are in (or app.module.ts if you are not in a specific module). To import these come from

import { FormsModule, ReactiveFormsModule } from '@angular/forms';

If you put it in a sub-module, you should not also reference the ReactiveFormsModule in a parent module that imports the module you are in.

I have created a working example for you on StackBlitz based on your StackBlitz example.

Bren Gunning
  • 153
  • 2
  • 9
  • I just did but it's still not working. Added both modules into survey.module.ts but I'm still having this error –  Jul 12 '19 at 11:57
  • And you removed the Forms modules (both) from the `app.module.ts`? I noticed you had that in the two places, on your StackBlitz. – Bren Gunning Jul 12 '19 at 12:54
0

surveypage.module.ts.module.ts

import { FormsModule, ReactiveFormsModule } from '@angular/forms';

    @NgModule({
  imports: [
    CommonModule,
    FormsModule,
    ReactiveFormsModule,
    IonicModule,
    RouterModule.forChild(routes)
  ],
  declarations: [ForgotpassPage]
})

surveypage.html

    <form [formGroup]="forgot_form" autocomplete="off">
    <ion-item lines="none" class="input-container">
    <ion-label position="floating" class="input-label">
      Email address
    </ion-label>
    <ion-input type="email" formControlName="email" class="input-box"></ion-input>
  </ion-item></form>

surveypage.ts

    forgot_form: FormGroup;
    constructor(private formBuilder: FormBuilder){}
MohammedAli
  • 2,361
  • 2
  • 19
  • 36
  • this form is working but my case is that my form is in an external component which has no modules. I just tried your code inside my page, I had not this error anymore. But this code inside the component which is in my page shows the error I wrote in the title –  Jul 12 '19 at 12:17