I'm looking at this in my browser:
<input class="ng-valid-number ng-dirty ng-valid ng-valid-required" type="number" step="0.01" required="" data-ng-model="obfuscated" min="0.1" max="0.5">
That seems strange to me, given the fact that I filled in 42 as a value.
I'd like to use a custom validation function. I don't care for a directive a this point, I just want to do something along the lines of
ng-valid-when="expression"
Does such a thing exist?
(If you're wondering how I got this to fail, the clue is to use an espression to fill max and min max="0.5" works as expected, max="{{my expression}}" doesn't.)
UPDATE: working directive solution
With a directive:
module.directive('withinRange', function () {
return {
require: 'ngModel',
link: function (scope, element, attrs, ngModel) {
var restrictions = scope.$eval(attrs.withinRange);
scope.$watch(function(){return ngModel.$modelValue}, function(){
ngModel.$setValidity('min', ngModel.$modelValue >= restrictions.min());
ngModel.$setValidity('max', ngModel.$modelValue <= restrictions.max());
});
}
}
});
this works:
<input name="input" type="number" step="0.01"
data-within-range="range"
data-ng-model="value"/>
angular.extend($scope, {value: 0.2,
range: {
min: function () {
return 0.1;
}, max: function () {
return 0.9;
}}});