
为了使它起作用,我需要添加“返回值”;在异步调用之外。下面的代码。
commonModule.directive("usernameVerify", [ 'userSvc', function(userSvc) { return { require: 'ngModel', scope: false, link: function(scope, element, attrs, ctrl) { ctrl.$parsers.unshift(checkForAvailability); ctrl.$formatters.unshift(checkForAvailability); function checkForAvailability(value) { if (value.length < 5) { return value; } userSvc.userExists(value) .success(function(alreadyUsed) { var valid = alreadyUsed === 'false'; if (valid) { ctrl.$setValidity('usernameVerify', true); return value; } ctrl.$setValidity('usernameVerify', false); return undefined; }); // Below is the added line of pre. return value; } } } }]);欢迎分享,转载请注明来源:内存溢出
微信扫一扫
支付宝扫一扫
评论列表(0条)