【发布时间】:2014-12-19 09:43:34
【问题描述】:
我有一个“uniqueCheck”指令,它检查值是否已经存在于列表中,并相应地验证 ngModel。该指令在输入标签上使用时按预期工作,但在呈现输入标签的指令上使用时,结果与预期不符。
指令中的验证器函数被调用,但它不会验证或使输入的 ngModel 无效。
您可以在提供的 plnkr 链接上查看指令的完整代码
Plnkr 链接:plnkr
html如下:
<--! when used with a directive -->
<my-wrapper ng-model="values.abc" unique-check="" list="list" prop="name"> </my-wrapper>
<--! when used on an input tag-->
<div ng-form="myform">
<input type="text" unique-check
list="list" prop="name"
name="myfield"
ng-model="values.pqr"/>
<span>isDuplicate:{{myform.myfield.$error.isDuplicate}}</span>
</div>
【问题讨论】:
标签: javascript angularjs validation angularjs-directive angularjs-validation