如何从代码中获取$index
的实际值?
我的HTML是:
<div class="list-group nav nav-stacked">
<a
ng-repeat="data in dbdata | orderBy:'heading' | filter:tocsearch"
ng-click="jumpToManual(data.user_manual_id)"
class="list-group-item"
ng-class="{'active':data.user_manual_id===manualdata.page_id, 'selected': selectedIndex}">
{{data.heading}}
</a>
</div>
<button class="btn btn-default pull-right" ng-click="nextManual(data.$index)" type="button">Next →</button>
目标是使用nextManual函数在ng-repeat之外实现一个按钮,其中ng-repeat的$ index被传递。
答案 0 :(得分:1)
您可以将$parent.$index
作为参数传递给ngClick函数:
<div class="list-group nav nav-stacked">
<a ng-repeat="data in dbdata | orderBy:'heading' | filter:tocsearch"
ng-click="jumpToManual(data.user_manual_id, $parent.$index)"
class="list-group-item"
ng-class="{'active':data.user_manual_id===manualdata.page_id, 'selected': selectedIndex}">
{{data.heading}}
</a>
</div>