使用ng-init给首层的每个元素赋值一个独立的值。
ng-init="outerIndex = $index;"
HTML:
<div class="category-nav">
<div class="category-nav-header">资源分类</div>
<div class="category-nav-cell" ng-repeat="firstItem in firstCategorys track by $index" ng-init="outerIndex = $index;">
<div class="category-nav-cell-header">
<h4 class="category-nav-firstTitle" ng-click="clickFirstCategory($index)">{{firstItem}}</h4>
<img src="" alt="" class="category-nav-expand" ng-click="showOrHiden($index)">
</div>
<div class="category-nav-secondContain" ng-if="categoryStatus[$index]">
<div class="category-nav-second" ng-repeat="secondItem in secondCategory[$index]" ng-click="clickNavSecondCategory(outerIndex,$index)">{{secondItem}}</div>
</div>
</div>
</div>
JS:
$scope.clickNavSecondCategory = function (outerIndex,innerIndex) {
console.log('点击了导航栏的分类页码'+outerIndex+innerIndex);
$scope.showMainContentSecondCategory = false;
$scope.routes.splice(1,2,$scope.firstCategorys[outerIndex],$scope.secondCategory[outerIndex][innerIndex]);
};