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