我正在尝试让Angular根据我的数据生成CSS滑块。我知道数据已经存在并且能够为按钮生成它,但是代码由于某种原因无法填充ng-switch-when。当我检查代码时,我发现这个出现了两次(我知道这是正确的,因为我只有两个项目):
<div ng-repeat="assignment in assignments" ng-animate="'animate'" class="ng-scope">
<!-- ngSwitchWhen: {{assignment.id}} -->
</div>
我的实际代码:
<div ng-init="thisAssignment='one'">
<div class="btn-group assignments" style="display: block; text-align: center; margin-bottom: 10px">
<span ng-repeat="assignment in assignments">
<button ng-click="thisAssignment = '{{assignment.id}}'" class="btn btn-primary">{{assignment.num}}</button>
</span>
</div>
<div class="well" style="height: 170px;">
<div ng-switch="thisAssignment">
<div class="assignments">
<div ng-repeat="assignment in assignments" ng-animate="'animate'">
<div ng-switch-when='{{assignment.id}}' class="my-switch-animation">
<h2>{{assignment.name}}</h2>
<p>{{assignment.text}}</p>
</div>
</div>
</div>
</div>
</div>
编辑:这是我试图模拟的内容,但使用动态数据。 http://plnkr.co/edit/WUCyCN68tDR1YzNnCWyS?p=preview
assignment
,但是在重复器块中,您具有相同名称的迭代器变量assignment
,然后在块内进行分配。您应该尝试更改用于跟踪所选内容的属性名称,例如selectedAssignment。 - Jon Jaques