title: angularjs $setValidity not working while checking for email uniqueness
body: <p>I use a directive to check if the email is already registered in my DB.</p>
  
  <pre><code>app.directive('uniqueEmail', function($http) {
      var toId;
      return {
          restrict: 'A',
          require: 'ngModel',
          link: function(scope, elem, attr, ctrl) { 
          //when the scope changes, check the email.
          scope.$watch(attr.ngModel, function(value) {
                  // if there was a previous attempt, stop it.
                  if(toId) clearTimeout(toId);
                  // start a new attempt with a delay to keep it from
                  // getting too "chatty".
              toId = setTimeout(function(){
                  // call to some API that returns { isValid: true } or { isValid: false }
                      $http.get('check/e/' + value).success(function(data) {
                      //set the validity of the field
                          ctrl.$setValidity("uniqueEmail", data.isValid);
                      });
                  }, 200);
          })
          }
      }
  }); 
  </code></pre>
  
  <p>and my input :</p>
  
  <pre><code>&lt;form name="myForm"&gt;    
  &lt;input type="email" ng-model="userEmail" name="userEmail" required unique-email/&gt;
  &lt;tt&gt;myForm.userEmail.$error = {{myForm.userEmail.$error}}&lt;/tt&gt;
  &lt;/form&gt;
  </code></pre>
  
  <p>My problem is that the $error.uniqueEmail is always false. the $http response shows false when email is available and true when email is already registered. (adding alert(data.isValid) confirms that.</p>
  
  <p>I also tryed to switch the true/false statement from the $http reponse without sucess (email already registered = false and email available = true).</p>
  
  <p>What am i missing ?</p>
  
  <p><strong>Edit :
  Ok i found the problem</strong> </p>
  
  <ol>
  <li><code>ctrl.$setValidity("uniqueemail", false) shows true</code>  and <code>ctrl.$setValidity("uniqueemail", true) shows false</code></li>
  <li>the reponse of the http was {"isValid":"true"} and it must be {"isValid":true} (whithout quotes)</li>
  <li>I switched the true/false statement from the http response, so when an error has to be triggered (email already registered) the response must be {"isValid":false}</li>
  </ol>