I did this directive to validate a number if it is in a range:
app.directive('nkNumber', function(){
return {
scope: {
max: '=nkMax',
min: '=nkMin'
},
require: 'ngModel',
restrict: 'A',
link: function($scope, iElm, iAttrs, controller) {
function validate(value){
if (angular.isDefined(value)){
value = parseInt(value);
if ($scope.max){
var max = parseInt($scope.max);
controller.$setValidity('nkMax', value < max)
}
if ($scope.min){
var min = parseInt($scope.min);
controller.$setValidity('nkMin', value > min)
}
}
return value;
}
controller.$parsers.push(validate);
controller.$formatters.push(validate);
}
};
});
The validation works fine, but my model isn't updated when I change the value on the input.
Why is this happening? How can I solve it?
1.0.3it stop to work...I'm using the1.0.5... plnkr.co/edit/qRc8JClqCc5DFTjigrxL?p=preview