I have some webapp to change. I made some changes with ng-repeat, new JSON looks like this:
[
{
"styl":"nowoczesny",
"dzieci":[
{
"id":53,
"bookmark":true,
"rodzina":"Nekko",
"page":1
},
{
"id":69,
"bookmark":true,
"rodzina":"Krak",
"page":2
},
{
"id":81,
"bookmark":true,
"rodzina":"Oxen",
"page":3
},
{
"id":93,
"bookmark":true,
"rodzina":"Spirala",
"page":4
}
]
},
{
"styl":"klasyczny",
"dzieci":[
{
"id":109,
"bookmark":true,
"rodzina":"Vello",
"page":5
},
{
"id":127,
"bookmark":true,
"rodzina":"Renzo",
"page":6
},
{
"id":135,
"bookmark":true,
"rodzina":"Zenit",
"page":7
}
]
}
]
HTML like this:
<ul>
<li ng-repeat="l in list">
{{l.styl}}
<ul>
<li ng-repeat="dziecko in l.dzieci | filter:search "
ng-class="{active:isActiveTab(dziecko)}" ng-click="openItem(dziecko)">
{{dziecko.rodzina}}
<b>{{dziecko.page}}</b>
</li>
</ul>
</li>
Everything works fine despite openItem method, its first version looks like this:
$scope.openItem = function(item) {
var index = $scope.list.indexOf(item),
length = $scope.list.length;
$scope.opened = item;
$scope.next = $scope.list[index+1];
$scope.prev = $scope.list[index-1];
};
How should I modify it to make it works with above html code. I try $index but angular throws an error. (I need to open a new pdf page once I click on a sub-li item on the list).
Thx in advance!