I'm an angular newbie, and I'm stumbling over something in how angular's form validation directives work.
I know that I can fairly easily add directives to individual fields, but I'm trying to add a validation which will compare two form fields (both of which are elements of a model).
Here's a form skeleton:
<form name="edit_form" >
<input name="min" type="number" ng-model="field.min"/>
<input name="max" type="number" ng-model="field.max"/>
</form>
<div class="error" ng-show="edit_form.min.$dirty || edit_form.max.$dirty">
<small class="error" ng-show="(what goes here?)">
Min cannot exceed max
</small>
</div>
In short, I want to write a directive and use it to show/hide this small.error
if min
and max
both have values but min > max
. How can I access both fields inside one directive? Is a directive the right tool for this job?
See Question&Answers more detail:
os 与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…