我有这个指令(从https://stackoverflow.com/a/16242433/40676复制)
app.directive("dwMin", [function () {
return {
restrict: 'A',
require: 'ngModel',
link: function (scope, element, attributes, modelController) {
scope.$watch(attributes.dwMin, function () {
modelController.$setViewValue(modelController.$viewValue);
});
var minValidator = function (value) {
var min = scope.$eval(attributes.dwMin) || 0;
if (!isEmpty(value) && value < min) {
modelController.$setValidity('dwMin', false);
return undefined;
} else {
modelController.$setValidity('dwMin', true);
return value;
}
}
modelController.$parsers.push(minValidator);
modelController.$formatters.push(minValidator);
}
}
}]);
我像这样使用它
<span>min.</span><input type="text" data-ng-model="productFormData.product.MinimumDepositAmount"/>
<span>max.</span><input type="text" dw-min="{{productFormData.product.MinimumDepositAmount}}" data-ng-model="productFormData.product.MaximumDepositAmount" />
但是当我更改最小值时,不会在 dw-min 指令中触发手表。为什么是这样?我该怎么做才能让手表被解雇?