我有两个输入,我需要使用以下限制验证每个字段:值B 必须始终小于值A ,否则显示错误消息。这是example。
我知道我需要创建一个指令,但我甚至不知道如何开始。
HTML 的
<form name="exampleForm">
<label>Value A</label>
<input type="number" name="valueA" data-ng-model="valueA" required="required"/>
<div ng-messages="exampleForm.valueA.$error">
<div ng-message="required">This field is required</div>
</div>
<p>
<label>Value B</label>
<input type="number" name="valueB" data-ng-model="valueB" required="required"/>
<div ng-messages="exampleForm.valueB.$error">
<div ng-message="required">This field is required</div>
</div>
</form>
答案 0 :(得分:0)
<input type="number" name="valueB" data-ng-model="valueB" max="{{ valueA - 1 }}" required="required"/>
<div ng-messages="exampleForm.valueB.$error">
<div ng-message="required">This field is required</div>
<div ng-message="max">This field is too large</div>
</div>