AngularJs Select在ng重复选择名称中,未识别$index
我在ng repeat中有一个select语句。我使用$index值为每个选择获取唯一的名称。然后我使用这个名称来检查验证。当不在重复中时,验证工作正常,但在重复中,所需选择周围的红色框不会显示 这是小提琴 非常感谢您的帮助 另外,点击+号在小提琴中添加更多的行AngularJs Select在ng重复选择名称中,未识别$index,angularjs,select,indexing,required,ng-repeat,Angularjs,Select,Indexing,Required,Ng Repeat,我在ng repeat中有一个select语句。我使用$index值为每个选择获取唯一的名称。然后我使用这个名称来检查验证。当不在重复中时,验证工作正常,但在重复中,所需选择周围的红色框不会显示 这是小提琴 非常感谢您的帮助 另外,点击+号在小提琴中添加更多的行 * {{$index}} * 问题是在ng repeat中生成的name属性没有在表单控制器变量上生成正确的属性。在你的情况下是这样的 {“selectOutside”:{},selectInside{{{$index}}:{}
*
{{$index}}
*
问题是在ng repeat
中生成的name属性没有在表单控制器变量上生成正确的属性。在你的情况下是这样的
{“selectOutside”:{},selectInside{{{$index}}:{}
您可以选择在每次重复时声明一个子表单,然后使用相同的变量名称并检查错误
有关详细信息,请参阅此帖子您是否可以尝试表达式
testForm['selectInside'+$index].$error.必填项
Nope,该选项无效。单击提交按钮时,您可以看到验证错误。参见JSFIDLE
<form name="testForm">
<select name="selectOutside"
class="span2" ng-model="plugin.selectedDevice"
ng-options="item.ID as item.Title for item in devices" ng-required="true">
<option style="display:none" value=""></option>
</select>
<span class="error" ng-show="testForm.selectOutside.$error.required">
*
</span><br>
<a class="btn" ng-click="addPlugin()">
<i class="glyphicon glyphicon-plus"></i></a>
<table>
<tr ng-repeat="plugin in plugins">
<td><strong>{{$index}}</strong>
</td>
<td>
<select name="selectInside{{$index}}" class="span2"
ng-model="plugin.selectedDevice"
ng-options="item.ID as item.Title for item in devices" ng-required="true">
<option style="display:none" value=""></option>
</select>
<span class="error"
ng-show="testForm.selectInside{{$index}}.$error.required">
*
</span>
</td>
</tr>
</table>
</form>