-2

Is it possible to affect a unique Id to a div located inside two ng-repeat directives? See bellow example:

<!--data: [[{id: 'A'},{id: 'B'},{id: 'C'}], [{id: 'X'},{id: 'Y'}]]-->
<div ng-repeat = "item in data">
     <div ng-repeat = "sub-item in item">
        <div id = "{{$index}}">
     </div>
</div>

expected output:

<!--first ng-repeat-->
<div id = "1">
<div id = "2">
<div id = "3">
<div id = "4"> <!--start second array-->
<div id = "5">

Not:

<div id = "1">
<div id = "2">
<div id = "3">
<div id = "1"> <!--start second array-->
<div id = "2">

Update: I don't think track by or $parent.$index will work for this use case, obviously we have to calculate the length of each sub-array in order to get exact incremented counter. I'm currently trying a combination of two ng-init. I will update the post once I get something working

Nourdine Alouane
  • 804
  • 12
  • 22

1 Answers1

0

I finally got it to work, here is my attempt:

<div ng-repeat = "item in data" ng-init = "count = 0">
 <div ng-repeat = "sub-item in item" ng-init="count = count + data[$parent.$index -1].length">
    <div id = "{{count+$index+1}}">
 </div>

Feel free to edit if you have a more suitable solution

Nourdine Alouane
  • 804
  • 12
  • 22