使用 angularjs 中的属性指令获取未定义的指令范围值

getting directive scope values as undefined with attribute directive in angularjs

angularjs 指令中声明的作用域变量未定义。 以下代码有什么问题?

<input type="text" class="form-control" id="amount"
 name="amount" ng-model="amount" required ng-pattern="Pattern"
 min="25" max="{{availableAmount}}" input-range-check/>

脚本

app.directive('inputRangeCheck', function () {
    return {
        restrict: 'A',
        require: 'ngModel',
        scope: {
            min: '@',
            max: '@'
        },
        link: function (scope, element, attributes, ngModel) {          
            ngModel.$validators.minError = function (modelValue) {
                console.log("--------------------------",min)
                return modelValue < min;
            };
            ngModel.$validators.maxError = function (modelValue) {
                return modelValue > max;
            };          
            scope.$watch(attributes.ngModel, function(value) {
                ngModel.$validate();
            });
        }
    };
});

在 link 函数中得到未定义的最小值和最大值?

范围对象中有最小值和最大值。

这个功能让你一目了然。

  link: function (scope, element, attributes, ngModel) {          
        ngModel.$validators.minError = function (modelValue) {
            console.log("--------------------------",scope.min)
            return modelValue < scope.min;
        };
        ngModel.$validators.maxError = function (modelValue) {
            return modelValue > scope.max;
        };          
        scope.$watch(attributes.ngModel, function(value) {
            ngModel.$validate();
        });
    }