У меня есть этот код, и я хочу иметь один индекс для всех элементов во втором ng-repeat. Прямо сейчас индексы выглядят так:
0 0
0 1
0 2
1 0
1 1
1 2
И я хочу, чтобы они выглядели так:
0 0
0 1
0 2
1 3
1 4
1 5
И если я ищу "qwe", я хочу, чтобы это выглядело следующим образом
0 0
0 1
0 2
Как мне этого добиться (обратите внимание на ng-if, который фильтрует текст)?
var app = angular.module('github', []);
app.controller('githubRepos', ['$scope','$http', function($scope, $http){
$scope.text = '';
$scope.groups = {
1: ['asd', 'asd1', 'asd2'],
2: ['qwe', 'qwe1', 'qwe2']
}
$scope.show = function(text) {
return !$scope.text || text.indexOf($scope.text) !== -1;
}
}]);
<script src="https://ajax.googleapis.com/ajax/libs/angularjs/1.2.23/angular.min.js"></script>
<div ng-app="github">
<div ng-controller="githubRepos">
<input type="text" ng-model="text" />
<div ng-repeat="group in groups track by $index" ng-init="parentIndex = $index">
<div ng-repeat="item in group track by $index" ng-if="show(item)">
{{parentIndex}} {{$index}} {{item}}
</div>
</div>
</div>
</div>