AngularJS | input Directive
Input is an HTML tag which is used to get user input.ng-model is an angular directive which is used for data binding(i.e.,reference to the input element is provided by the ng-model). These both are combined to modify the input field.
The following states are established to the input field whose value is true for the following.
- $untouched: when the field has not been touched
- $touched: when the field has been touched
- $pristine: when the field has not been modified
- $dirty: when the field has been modified
- $invalid: when the field content is not valid
- $valid: when the field content is valid
Example: $valid state for the required input field in a form is explained below
For the above-mentioned input directive, few CSS classes are added. They 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.
- ng-invalid-key: One key for each validation.
The classes are removed if the value is false.
If the input field is used along with the required attribute, valid (when there is an input it is set to true) and invalid (when there is no input it is set to true) states are established. The classes are removed if the value is false.