Follow

Keep Up to Date with the Most Important News

By pressing the Subscribe button, you confirm that you have read and are agreeing to our Privacy Policy and Terms of Use
Contact

Angular 16 – error NG8002: Can't bind to 'ngModel' since it isn't a known property of 'input'

I have the above error message when I try to use two-way binding in a Angular application.

<form>
 <input type="email" class="form-control" id="email" name="email" required [(ngModel)]="email" />
</form>

The code is in the loginComponent which was created in this folder: src/app/login.

I’ve imported forms in the app.module.ts like this :

MEDevel.com: Open-source for Healthcare and Education

Collecting and validating open-source software for healthcare, education, enterprise, development, medical imaging, medical records, and digital pathology.

Visit Medevel

import { FormsModule, ReactiveFormsModule } from '@angular/forms';
...
@NgModule({
...
imports: [
    BrowserModule,
    AppRoutingModule,
    FormsModule,
    ReactiveFormsModule
  ],
...
providers: [],
  bootstrap: [AppComponent],
})

restarted the app, but the error is still there.

Please help me with this situation.

Thank you!

>Solution :

The html to which the component belongs to must be a standalone component. If that is the case, you need to separately add FormsModule to the imports array!

@Component({
  selector: '<<some-component>>',
  standalone: true,
  imports: [FormsModule],
  ...
})
Add a comment

Leave a Reply

Keep Up to Date with the Most Important News

By pressing the Subscribe button, you confirm that you have read and are agreeing to our Privacy Policy and Terms of Use

Discover more from Dev solutions

Subscribe now to keep reading and get access to the full archive.

Continue reading