FormsModule provides Angular directives and providers for template-driven and reactive forms. In a standalone component, add it to the component-level imports array to enable ngModel. section 2.3.1
Standalone login form
A LoginComponent imports FormsModule and binds email and password inputs with [(ngModel)]="credentials.email" and [(ngModel)]="credentials.password". This keeps entered credentials synchronized with component state. section 2.3.1
Listing 2.7 Standalone component importing a module
@Component({
selector: 'app-login',
template: `
<div class="login-container">
<h1>Login</h1>
<form>
<input type="text" name="email"
placeholder="Email"
[(ngModel)]="credentials.email" /> #1
<input type="password" name="password" placeholder="Password"
[(ngModel)]="credentials.password">
<button type="submit">Login</button>
</form>
</div>
`,
standalone: true,
imports: [FormsModule], #2
})
export class LoginComponent {
credentials = { email: '', password: '' };
}
Shows the component-level FormsModule import alongside two-way ngModel bindings. section 2.3.1
