[英]Use $setValidity in ng-repeat input
I have a form that it repeated in a ng-repeat. 我有一个在ng-repeat中重复的形式。 I put part of my form in blow. 我吹了一部分表格。 for custom validation I want to use $setValidity in controller. 对于自定义验证,我想在控制器中使用$ setValidity。 But I cant to get input name by index in controller. 但是我无法通过控制器中的索引获取输入名称。 How I use $scope.form.name1.$setValidity("size", false) and other input element? 如何使用$ scope.form.name1。$ setValidity(“ size”,false)和其他输入元素?
<form name="form">
<div ng-repeat="item in items track by $index">
<input name='name{{$index}}' ng-model="name{{$index}}">
</div>
</form>
function validation(index){
if(...){
$scope.form.name.$setValidity("size", false); // form.name0 and form.name1 and ...
}
}
可以使用括号表示法 。
$scope.form["name" + index].$setValidity("size", false);
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.