AngularJS ng-model Directive


The ng-model directive binds the value of HTML controls (input, select, textarea) to application data.


The ng-model Directive

With the ng-model directive you can bind the value of an input field to a variable created in AngularJS.

Output :

Two-Way Binding

The binding goes both ways. If the user changes the value inside the input field, the AngularJS property will also change its value:

Output :

Validate User Input with AngularJS

The ng-model directive can provide type validation for application data using attributes like:

Output :

Application Status

The ng-model directive can provide status for application data (valid, dirty, touched, error):

Output :

CSS Classes

The ng-model directive provides CSS classes for HTML elements, depending on their status:

Output :