title: I need to validate email is unique, when user enters his email during registration.This should happen on tab function in Angular Js
body: <p>On tab functionality control should go to server and check for unique email id and return success or fail mentioned in the errorMessage.</p>
  
  <p>I have written below code and tried using ng-change,ng-blur but control is not hitting.</p>
  
  <p><strong>Controller.js</strong></p>
  
  <pre><code>checkUniqueEmail(emailId);
  function checkUniqueEmail(emailId) {
      MerchantRepository.checkUniqueEmail(emailId)
      .then(function (response){
         scope.errorMessage=response.data;
      },
      function(errResponse){
         console.error('Error while fetching Produce Info:Merchant Side');
      }
      );
  };
  </code></pre>
  
  <p><strong>Repository.js</strong></p>
  
  <pre><code>this.checkUniqueEmail = function(emailId){
  
     var defer = $q.defer(); 
     //defer is units of work,promise is data from those defer
     var merchantEmailPromise =  http.post('/ABCD1.3/checkMerchantEmail/',emailId);
  
     merchantEmailPromise.then(function(response){ 
        errorMessage =response;
        defer.resolve(errorMessage);
     });
     return defer.promise;
  };
  </code></pre>
  
  <p><strong>Reg.html</strong></p>
  
  <pre><code>&lt;div class="col-sm-5 form-group"&gt;
      &lt;input type="email" style="width: 250px; height:40px;" class="form-control"
      name="emailId" 
      ng-model="merchant.emailId" placeholder="Enter  Email Id"
      ng-minlength="5" ng-maxlength="50"
      ng-change="checkUniqueEmail(emailId)" /&gt;
      {{errorMessage}}
  &lt;/div&gt;
  </code></pre>
  
  <p>Can anyone help with this,
  tried lot more times and left out blank.</p>
  
  <p>Thank you</p>