我尝试在选中上一个选择时显示一个选择。
<div ng-repeat="item in collection">
<div ng-show="$index === 0 || $parent.list[$index].nom">
<select ng-model="$parent.list[$index].nom" ng-options="..."></select>
</div>
-
<div ng-repeat="item in collection">
我循环遍历集合并创建许多选择集合中有项目。
-
<div ng-show="$index === 0 || $parent.list[$index].nom">
我想在两个条件下显示/隐藏选择的父 div:
- 如果索引等于 0 则显示 div(用于显示第一个选择)
- 如果当前 ngModel 包含名称,我会显示 div
-
<select ng-model="$parent.list[$index].nom" ng-options="...">
我放置了一个动态的 ngModel,其中每个选择都有自己的模型,例如:
(来源:noelshack.com)
测试示例:我在一个选择中有三个选项,所以我想给成员(member)机会选择每个选项。
如果成员选择选项 1,则第二个选择显示,如果他选择第二个选项,则选择第三个选择显示,但不再选择其他...
这里的问题: 指令 ngShow 中的 $index 似乎在这种情况下已知:
$index === 0
但这里没有:
$parent.list[$index].nom
最佳答案
您必须在您的 ng-repeat 中包含 track by $index
...
<div ng-repeat="item in collection track by $index>
关于angularjs - ng-show 中 $index 的可访问性,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/35228818/