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

Why ngModel doesn't works on the last version of Angular 17?

I am trying to make a form in my angular app, but when i want to implement ngModel on my form :

    <form (ngSubmit)="onSignUp()" #signupForm="ngForm">
        <h1>Connexion</h1>
        <input type="email" name="mail" [(ngModel)]="userLogin.email" placeholder="Email" />
        <input type="password" name="mdp" [(ngModel)]="userLogin.password" placeholder="Password" />
        <a href="#">Mot de passe oublie ?</a>
        <button type="submit">Se Connecter</button>
    </form>

I have this error :

NG8002: Can’t bind to ‘ngModel’ since it isn’t a known property of ‘input’. [plugin angular-compiler]

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

I can’t import FormsModule in the app.module.ts because this file doesn’t exists on Angular 17, i only have an app.config.ts file.

Can someone please explain me how to do?

>Solution :

if your component is set with standalone: true, then you need to add FormsModule to the imports array of the component!

Since its standalone, we need to add all the necessary dependencies to the imports array!

@Component({
  ...
 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