以下验证指令运行良好。任何人都可以帮我转换为angularjs 1.3 $ validators语法。最早的任何帮助都会非常感激。
(function () {
'use strict';
angular.module('myApp').directive('validFees', function () {
return {
restrict: 'A',
require: 'ngModel',
scope: {
studentCategory: '='
},
link: function (scope, element, attrs, ngModel) {
scope.$watch(function () {
var modelValue = ngModel.$modelValue || ngModel.$$invalidModelValue;
var studentCategory = scope.studentCategory;
if (studentCategory === 'HandiCaped') {
return modelValue !== 'FeesShouldBePaid';
} else {
return true;
}
}, function (validity) {
ngModel.$setValidity('validFees', validity);
});
}
};
});
}());
编辑:(我应该更简单地忽略上面的代码。请使用$ validators将下面的代码转换为1.30语法)
angular.module('myApp').directive('greaterThanFive', function () {
return {
restrict: 'A',
require: 'ngModel',
link: function (scope, element, attrs, ngModel) {
scope.$watch(function () {
var modelValue = ngModel.$modelValue || ngModel.$$invalidModelValue;
return modelValue > 5;
}, function (validity) {
ngModel.$setValidity('greaterThanFive', validity);
});
}
};
});