AngularJS has inbuilt mechanism to identity the validity of the input element values and set css classes accordinlgy so that we can visually notify the user about it.
For that purpose, AngularJS model set one of following css classes to the input elements (note that AngularJS doens't have these classes defined so we need to define ourselves). All these css classes are set only after the element looses its focus (blurred)
In following code snippet, we have defined above css classes.
<style>
.ng-valid{
background-color:green;
color:white;
}
.ng-invalid{
background-color:red;
color:black;
}
.ng-pristine{
background-color:#9c914c;
}
</style>
<div ng-app>
<h4>Valid values</h4>
<p>String: <input type="text" ng-model="txtValue" required /> | {{ txtValue }}</p>
<p>Email: <input type="email" ng-model="emailValue" required /> | {{ emailValue }}</p>
<p>Number: <input type="number" ng-model="numberValue" required /> | {{ numberValue }}</p>
<p>Date: <input type="date" ng-model="dateValue" required /> | {{ dateValue }}</p>
<p>URL: <input type="url" ng-model="urlValue" required /> | {{ urlValue }}</p>
</div>
In the HTML block, we have following input elements and its css class is set by AngularJS as per their values
Output
Views: 16699 | Post Order: 47