Angularjs

时间:2018-04-02 05:58:56

标签: javascript html angularjs spring

在注册表单中,我想进行复制检查。 何时重复,输入框下方会显示一条消息。

<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>

检查重复,我从服务器

计数
$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{
        ???????????????
    }

我对我应该写的内容感到非常困惑&#39; ???&#39;

事先,谢谢!

1 个答案:

答案 0 :(得分:4)

<强>控制器:

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>

我使用isDuplicate范围变量来显示消息。