I played with custom directives and prepared something that works for my business.
At my input for threshold , I have a less-than-or-equal="quota.size" that passes it the model property for verification (I want quota.threshold be less than or equal to quota.size ):
<input type="number" name="threshold" ng-model="quota.threshold" required less-than-or-equal="quota.size" />
In the link function of the lessThanOrEqual directive lessThanOrEqual he starts looking at quota.size , and when quota.size changes, he simply tries to set the current value of the threshold view on the model:
link: (scope, elem, attr, ctrl) -> scope.$watch attr.lessThanOrEqual, (newValue) -> ctrl.$setViewValue(ctrl.$viewValue)
Then there is a parser that validates by calling the scope.thresholdValidate(thresholdValue) method, passing it a candidate value. This method returns true if the test was successful, and if it happens, it returns a new value, otherwise - the current value of the model:
ctrl.$parsers.push (viewValue) -> newValue = ctrl.$modelValue if not scope.thresholdValidate viewValue ctrl.$setValidity('lessThanOrEqual', false) else ctrl.$setValidity('lessThanOrEqual', true) newValue = viewValue newValue
I push the parser to the parser compilation, as opposed to turning it off, as most examples show, because I want angular to check the required and number directives, so I can only get here if I have a valid and parsed number (less work for me, but for text inputs, I probably should parse)
Here is my playground: http://embed.plnkr.co/EysaRdu2vuuyXAXJcJmE/preview