Home > Blockchain >  Can't bind to 'ngModel' since it isn't a known property of 'input'.ngt
Can't bind to 'ngModel' since it isn't a known property of 'input'.ngt

Time:01-06

I receive the error can't bind to 'ngModel' since it isn't a known property of 'input' on my angular app, when i add a [(ngModel)]="email".

I already added import { FormsModule } from '@angular/forms'; in the app.module.ts but still doen't work, here is my code on sandbox.

https://codesandbox.io/s/intelligent-ives-czxn2?file=/src/app/modules/login/components/login-form/login-form.component.html

Thanks for your help

CodePudding user response:

Two things

  1. Your login-form.component is being declared in login.module.ts, which also needs the import for forms module
  2. Once you do that though, there is a new error saying the input needs a name on it. So just add name="email" as well.

login.module.ts:

import { NgModule } from "@angular/core";
import { CommonModule } from "@angular/common";
import { LoginComponent } from "./pages/login/login.component";
import { LoginFormComponent } from "./components/login-form/login-form.component";
import { FormsModule } from "@angular/forms";

@NgModule({
  declarations: [LoginComponent, LoginFormComponent],
  imports: [CommonModule, FormsModule]
})
export class LoginModule {}

login-form.component.html

<h1 >Connexion</h1>

<form>
  <input id="email" type="email" name="email" [(ngModel)]="email" />
  <input type="submit" />
</form>
  •  Tags:  
  • Related