Question
How to Fix "Can't bind to 'ngModel'" in Angular
Question
I am using Angular 4 and seeing this error in the console:
Can't bind to 'ngModel' since it isn't a known property of 'input'
How can I fix this error in Angular?
A typical example that triggers the issue looks like this:
<input [(ngModel)]="username">
export class AppComponent {
username = '';
}
What module or setup is required for ngModel to work correctly?
Short Answer
By the end of this page, you will understand why Angular does not recognize ngModel, how Angular modules control template features, and how to fix the error by importing FormsModule in the correct module. You will also learn common mistakes, how this differs from reactive forms, and how ngModel is used in real Angular applications.
Concept
ngModel is part of Angular's forms system. It enables two-way data binding between an input element and a component property.
For example:
<input [(ngModel)]="username">
This means:
- the input shows the value of
username - when the user types,
usernameupdates automatically
Angular does not make every directive available everywhere by default. Features such as ngModel, ngIf, and ngFor are provided by Angular modules.
ngModel belongs to FormsModule, which comes from @angular/forms.
If the Angular module that declares your component does not import FormsModule, Angular cannot understand [(ngModel)] in that component's template, so it throws this error:
Can't bind to 'ngModel' since it isn't a known property of 'input'
This matters because Angular uses modules to keep applications organized. Each module explicitly declares what template features it can use. That helps Angular compile templates correctly and keeps dependencies clear.
Mental Model
Think of Angular modules like a toolbox for each part of your app.
- Your component template is a worker.
ngModelis a tool.FormsModuleis the toolbox that contains that tool.
If the worker does not have that toolbox, it cannot use the tool.
So when Angular sees:
<input [(ngModel)]="username">
it asks: "Does this module have the forms toolbox?"
- Yes →
ngModelworks. - No → Angular says it does not know that property.
The important idea is: the component only gets access to directives imported by its Angular module.
Syntax and Examples
The most common fix is to import FormsModule into the Angular module that declares the component using ngModel.
import { NgModule } from '@angular/core';
import { BrowserModule } from '@angular/platform-browser';
import { FormsModule } from '@angular/forms';
import { AppComponent } from './app.component';
@NgModule({
declarations: [AppComponent],
imports: [BrowserModule, FormsModule],
bootstrap: [AppComponent]
})
export class AppModule {}
Then your component template can use ngModel:
<input [(ngModel)]="username" placeholder="Enter your name">
<p>Hello, {{ username }}</p>
import { Component } from '@angular/core';
@Component({
selector: 'app-root',
templateUrl: './app.component.html'
})
export class AppComponent {
username = '';
}
What [(ngModel)] means
The syntax is called banana in a box:
[(ngModel)]="username"
It combines:
[ngModel]="username"
(ngModelChange)="username = $event"
So Angular both:
- reads the value from the component
- writes changes back to the component
Feature module example
If your component is declared in a feature module, importing FormsModule only in AppModule may not be enough.
import { NgModule } from '@angular/core';
import { CommonModule } from '@angular/common';
import { FormsModule } from '@angular/forms';
import { ProfileComponent } from './profile.component';
@NgModule({
declarations: [ProfileComponent],
imports: [CommonModule, FormsModule]
})
export class ProfileModule {}
The key rule is: import FormsModule in the same module where the component is declared.
Step by Step Execution
Consider this example:
import { Component } from '@angular/core';
@Component({
selector: 'app-root',
template: `
<input [(ngModel)]="name">
<p>{{ name }}</p>
`
})
export class AppComponent {
name = 'Ana';
}
And this module:
import { NgModule } from '@angular/core';
import { BrowserModule } from '@angular/platform-browser';
import { FormsModule } from '@angular/forms';
import { AppComponent } from './app.component';
@NgModule({
declarations: [AppComponent],
imports: [BrowserModule, FormsModule],
bootstrap: [AppComponent]
})
export class AppModule {}
What happens step by step
- Angular loads
AppModule. AppModuleimportsFormsModule.FormsModuleprovides thengModeldirective.- Angular compiles
AppComponent's template. - Angular sees
[(ngModel)]="name"on the<input>. - Because
FormsModuleis available in this module, Angular recognizesngModel. - The input displays the initial value:
Ana. - When the user types, Angular updates
name. - The
<p>{{ name }}</p>binding updates automatically.
What happens if FormsModule is missing
- Angular compiles the template.
- It sees
[(ngModel)]. - It checks available directives in the current module.
ngModelis not available.- Angular throws:
Can't bind to 'ngModel' since it isn't a known property of 'input'
So the problem is not the input element itself. The problem is that the forms directive was never imported into that module.
Real World Use Cases
ngModel is commonly used in simple and medium-sized Angular forms.
Common use cases
- Login forms
- bind email and password fields to component properties
- Search boxes
- update a query string as the user types
- Settings pages
- bind checkboxes, dropdowns, and text fields to user preferences
- Admin dashboards
- edit records in a quick form
- Filter UIs
- bind selected values for category, sort order, or date range
Example: search input
<input [(ngModel)]="searchTerm" placeholder="Search products">
<p>Searching for: {{ searchTerm }}</p>
export class ProductComponent {
searchTerm = '';
}
Example: checkbox
<label>
<input type="checkbox" [(ngModel)]="isAdmin">
Admin access
</label>
export class UserComponent {
isAdmin = false;
}
These are practical because the component state stays in sync with the form controls.
Real Codebase Usage
In real Angular projects, developers use ngModel mostly in template-driven forms and simple input binding scenarios.
Common patterns
- Quick forms for small features
- profile edit forms
- search fields
- filter panels
- Default values from APIs
- load data into component properties, then bind with
ngModel
- load data into component properties, then bind with
- Validation in templates
- combine
ngModelwithrequired,minlength, and template references
- combine
- Guarding incomplete values
- initialize properties to safe defaults like
'',false, or0
- initialize properties to safe defaults like
Example: simple validation
<input [(ngModel)]="email" #emailCtrl="ngModel" required>
<p *ngIf="emailCtrl.invalid && emailCtrl.touched">
Email is required.
</p>
Example: safe defaults
export class SettingsComponent {
displayName = '';
receiveEmails = false;
}
In larger codebases
Developers often choose:
ngModelfor simple forms- Reactive Forms for complex validation and dynamic forms
A common team guideline is:
- if the form is small and straightforward, use template-driven forms with
ngModel - if the form has complex validation, nested groups, or dynamic controls, use
ReactiveFormsModuleinstead
Common Mistakes
Here are the most common reasons this error keeps happening.
1. Forgetting to import FormsModule
Broken:
import { NgModule } from '@angular/core';
import { BrowserModule } from '@angular/platform-browser';
@NgModule({
imports: [BrowserModule]
})
export class AppModule {}
Fix:
import { FormsModule } from '@angular/forms';
@NgModule({
imports: [BrowserModule, FormsModule]
})
export class AppModule {}
2. Importing FormsModule in the wrong module
If UserFormComponent is declared in UserModule, then UserModule must import FormsModule.
A common mistake is importing it only in AppModule and expecting it to work everywhere.
3. Misspelling ngModel
Broken:
<input [(ngmodel)]="name">
Fix:
<input [(ngModel)]="name">
Angular template syntax is case-sensitive.
4. Using ngModel with reactive forms incorrectly
If you are using formControlName, mixing it with ngModel on the same control is usually not the right approach.
Problematic example:
<input formControlName="email" [(ngModel)]="email">
Usually, choose one form style for that control.
5. Forgetting standalone component imports in newer Angular versions
In newer Angular versions with standalone components, you import FormsModule in the component itself. Even though your original question is about Angular 4, many learners see this issue in modern Angular too.
6. Assuming every Angular directive is globally available
Angular does not automatically expose all directives. You must import the modules that provide them.
How to avoid these mistakes
- Check which module declares your component.
- Import
FormsModulethere. - Verify the spelling of
ngModel. - Do not mix template-driven and reactive patterns casually.
- Restart the dev server if the setup changed and the tooling seems stuck.
Comparisons
Here is how ngModel fits with related Angular form concepts.
| Concept | Purpose | Best for | Required module |
|---|---|---|---|
ngModel | Two-way binding in template-driven forms | Simple forms and inputs | FormsModule |
formControlName | Bind a control inside a reactive form group | Complex forms | ReactiveFormsModule |
[value] + (input) | Manual one-way binding plus event handling | Very simple custom handling | No forms module needed |
ngModel vs manual binding
With ngModel:
<input [(ngModel)]="name">
Manual equivalent:
<input [value]="name" (input)="name = $any($event.target).value">
ngModel is shorter and clearer for simple use cases.
Template-driven vs reactive forms
| Approach | Strengths | Trade-offs |
|---|---|---|
Template-driven (ngModel) | Easy to start, less code, good for small forms | Harder to scale for complex validation |
| Reactive forms | Strong structure, explicit validation, easier testing | More setup and boilerplate |
If your form is simple, ngModel is often enough. If your form becomes large or dynamic, reactive forms are usually better.
Cheat Sheet
Quick fix
import { FormsModule } from '@angular/forms';
@NgModule({
imports: [FormsModule]
})
export class AppModule {}
Basic usage
<input [(ngModel)]="name">
name = '';
Rule to remember
ngModelcomes fromFormsModule- import
FormsModulein the module that declares the component usingngModel
Two-way binding meaning
[(ngModel)]="name"
Equivalent idea:
[ngModel]="name"
(ngModelChange)="name = $event"
Common causes of the error
FormsModulenot imported- imported in the wrong module
- misspelled
ngModel - mixed incorrectly with reactive forms
When to use ngModel
- small forms
- search boxes
- settings panels
- simple data entry forms
When to consider reactive forms
- complex validation
- nested form groups
- dynamic controls
- large enterprise forms
FAQ
Why does Angular say ngModel is not a known property?
Because the module containing your component does not have access to FormsModule, which provides the ngModel directive.
Which module do I need to import for ngModel?
Import FormsModule from @angular/forms.
Why does importing FormsModule in AppModule not always fix it?
Because the component might be declared in a feature module. That feature module must also import FormsModule.
Can I use ngModel with reactive forms?
You should generally avoid mixing ngModel with formControlName on the same input unless you have a very specific reason and understand the trade-offs.
Is ngModel only for text inputs?
No. It also works with checkboxes, selects, textareas, and other compatible form controls.
What is the difference between ngModel and value binding?
ngModel handles both reading and writing automatically. [value] only sets the value unless you manually handle input events.
Do I still need this fix in newer Angular versions?
Yes, the idea is the same: Angular must have access to the forms module. In standalone components, the import location is different, but the principle is unchanged.
Mini Project
Description
Build a small profile form that lets a user edit their name, email, and newsletter preference using ngModel. This project demonstrates how template-driven binding works in a practical Angular component and reinforces the need to import FormsModule correctly.
Goal
Create a working Angular form where input fields stay synchronized with component properties and the current values are displayed live.
Requirements
- Import
FormsModulein the Angular module that declares the component. - Create a component with
name,email, andsubscribeproperties. - Bind a text input, email input, and checkbox using
[(ngModel)]. - Display the current values under the form.
- Initialize each property with a safe default value.
Keep learning
Related questions
@Directive vs @Component in Angular: Differences, Use Cases, and When to Use Each
Learn the difference between @Directive and @Component in Angular, including use cases, examples, and when to choose each.
Accessing Input Value from EventTarget in TypeScript
Learn why EventTarget has no value property in TypeScript and safely read values from HTML input events in Angular applications.
Angular (change) vs (ngModelChange): What’s the Difference?
Learn the difference between Angular (change) and (ngModelChange), when each fires, and which one to use in forms and inputs.