ng model Directive in AngularJS
ng-model Directive
The ng-model directive binds the value of HTML controls (input, select, textarea) to application data. It is a two-way binding i.e, If the user changes the value inside the input field, the AngularJS property will also change its value.
The purposes of ng-model directives are:-
-
Validate User Input i.e, this directive can provide type validation for application data.
-
Application Status i.e, this directive can provide status for application data.
-
CSS Classes i.e, this directive provides CSS classes for HTML elements.
The ng-model directive adds/removes the following classes:-
- ng-empty
- ng-not-empty
- ng-touched
- ng-untouched
- ng-valid
- ng-invalid
- ng-dirty
- ng-pending
- ng-pristine
Syntax:-
< element ng-model="name" >< /element >
Further Explanation:-
Value | Description |
---|---|
name | The name of the property you want to bind to the form field. |