AngularJS input Directive
AngularJS input Directive
AngularJS is used to change the default behavior of input elements by using an ng-model attribute. It provides data-binding as it becomes part of the AngularJS model and can be updated by AngularJS. Moreover, we can validate it and it has a $valid state. We can also do state control by it.
Input fields states are:-
- $untouched - The field has not been touched yet
- $touched - The field has been touched
- $pristine - The field has not been modified yet
- $dirty - The field has been modified
- $invalid - The field content is not valid
- $valid - The field content is valid
All of these states above have boolean values i.e, true or false.
We can change the style of each state by using the built-in CSS classes of the given states.
Form classes are:-
- ng-untouched - The field has not been touched yet
- ng-touched - The field has been touched
- ng-pristine - The field has not been modified yet
- ng-dirty - The field has been modified
- ng-valid - The field content is valid
- ng-invalid - The field content is not valid
- ng-valid-key - One key for each validation. Example: ng-valid-readonly.
- ng-invalid-key - Example: ng-invalid-required
Syntax:-
< input ng-model="name" >