ng-class validation is not working in AngularJS
<p>I tried to put green background if it is edited and valid.</p>

<p>But, even for invalid also it is showing green background. On invalid it should show the yellow background with red text.</p>

<p>Thanks in advance for giving me the solution.</p>

<h3>html</h3>

<pre><code>&lt;div ng-app="myApp" ng-controller="formCtrl"&gt;

    &lt;form name="inputform"&gt;
        &lt;div ng-class="{'has-success': inputform.email.$dirty &amp;&amp; inputform.email.$valid, 'has-error': inputform.email.$dirty &amp;&amp; inputform.email.$invalid}"&gt;
            &lt;label for="exampleInputEmail1"&gt;Email&lt;/label&gt;
            &lt;input type="text" name="email" ng-model="data.email" id="exampleInputEmail1" /&gt;
        &lt;/div&gt;
    &lt;/form&gt;

    {{data}}

&lt;/div&gt;
</code></pre>

<h3>javascript</h3>

<pre><code>var module = angular.module("myApp", []);

module.controller("formCtrl", ['$scope', function($scope){

    $scope.data = {};

}]);
</code></pre>

<h3>css</h3>

<pre><code>.has-error {
    color: red;
    background-color: red;
}

.has-success {
    color: black;
    background-color: green;
}
</code></pre>