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.
Thanks for your help
CodePudding user response:
Two things
- Your login-form.component is being declared in login.module.ts, which also needs the import for forms module
- 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>
