0

我有这个指令(从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 指令中触发手表。为什么是这样?我该怎么做才能让手表被解雇?

4

1 回答 1

1

{{ }}从传入的字符串中删除dw-minmodel引用属性中的时不需要插值。

dw-min="productFormData.product.MinimumDepositAmount"
于 2013-08-19T15:50:17.403 回答