【发布时间】:2019-04-02 10:26:31
【问题描述】:
在 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();
});
}
};
});
在链接函数中得到未定义的最小值和最大值?
【问题讨论】:
标签: angularjs angularjs-directive