demo20230512/Browser_Local/js/Directive/GreaterThan.js
2023-05-12 10:20:28 +08:00

34 lines
986 B
JavaScript

(function () {
'use strict';
angular
.module('View.Directive')
.directive('greaterThan', GreaterThanDirective);
//GreaterThanDirective.$inject = ['logService'];
function GreaterThanDirective() {
return {
require: '?ngModel',
scope: {
min: '@greaterThan'
},
link: function (scope, ele, attrs, ngModel) {
var min = parseFloat(scope.min);
if (!ngModel) return;
ngModel.$parsers.unshift(function (viewValue) {
var value = parseFloat(viewValue);
if (value > min) {
ngModel.$setValidity('greaterThan', true);
return viewValue;
} else {
ngModel.$setValidity('greaterThan', false);
return undefined;
}
});
}
};
}
}());