Re-checking email / id in Angularjs

In the registration form, I want to do a duplication check. When duplicated, a message appears under the input field.

<div class="form-group">
  <label class="col-md-2 control-label"><strong>Email</strong></label>
  <div class="col-md-10">
     <input type="email" class="form-control" name="usr_Email" 
            ng-model="usrEmail" ng-keyup="checkDuplicate()">
     <span class="help-block" 
           ng-show="signupForm.$submitted || signupForm.usr_Email.$touched">
        <div ng-show="?????" class="text-danger">is duplicated!</div>
     </span>
     </div>
</div>

to check the duplicate, I received the account number from the server

$scope.user.usrEmail = $scope.usrEmail;         
var req = {
        method: 'POST',
        url: './api/v1/public/checkDuplication',
        dataType: 'json',
        headers: { 
            'Content-Type': 'application/json; charset=utf-8'
        },
        data: angular.toJson($scope.user)
    };

$http(req).success(function(data, status, headers, config){
    $log.debug($filter('json')(data));
    if(data.number == 0){
        ???????
    }
    else{
        ???????????????
    }

I am very confused by what I have to write in '???'

Thanks in advance!

+4
source share
1 answer

Controller:

if(data.number == 0){
    //If email id is duplicate, then show the message in UI
      $scope.isDuplicate = true;    
} else{
   //If email id is not duplicate, then hide the message in UI
     $scope.isDuplicate = false;
}

HTML:

<div ng-show="isDuplicate" class="text-danger">is duplicated!</div>

I used the scope variable isDuplicateto display the message.

+4
source

Source: https://habr.com/ru/post/1695638/


All Articles