‘use strict‘; /* *检测用户名是否存在 */ angular.module(‘nswApp‘) .directive(‘checkname‘, function() { return { require: ‘ngModel‘, restrict: ‘A‘, scope: { checkName: ‘&checkName‘ } link: function(scope, elem, attrs, ctrl) { elem.on(‘blur‘, function() { var result = scope.checkName() .then(function(response) { if (response.value) { ctrl.$setValidity(‘checkname‘, false); } else { ctrl.$setValidity(‘checkname‘, true); } }, function(error) { }); }); } }; });
时间: 2024-10-27 04:36:40