angular自定义表单验证----用户名唯一

前端之家收集整理的这篇文章主要介绍了angular自定义表单验证----用户名唯一前端之家小编觉得挺不错的,现在分享给大家,也给大家做个参考。

angular




.directive('pwdCheck',['$http','httpLoadData',function($http,httpLoadData) {
    return {
        require: 'ngModel',link: function (scope,elem,attrs,ctrl) {
            elem.on('keyup',function () {
                            	var obj= {
"pwd":attrs.pwdCheck
   };
                	  var params ={
  requestParams:encodeURIComponent(JSON.stringify(obj)) // 参数需要 URL 编码s
  };
                    $http({
                        method: 'get',url:httpLoadData.setUrl+'/sf/service/user/check/password/rules',//根据换成自己的url
                        params:params
                    }).success(function(data) {
                    	var hide_show=false;
                    	if(data.length!=0){
			hide_show=true;
                    	}
                    	  console.log(obj)
                    	  console.log( data)
                          ctrl.$setValidity('pwdcheck',hide_show);
                    }).error(function(msg) {
                    	alert(msg)
                        ngModelController.$setValidity('unique',false);
                    });
            });
        }
    }
}
])
@H_502_24@ 
 


html

   <input user-check="{{dataForm.login}}" type="text" class="form-control" name="login" ng-model="dataForm.login"  ng-value="{{dataForm.login}}" /> 
    <div class="error" ng-show="adduserForm.login.$dirty &&adduserForm.login.$invalid">
   <span ng-show="adduserForm.login.$valid==false"> The username already exists!</span>

 </div>@H_502_24@ 原文链接:https://www.f2er.com/angularjs/149668.html

猜你在找的Angularjs相关文章