0

I am listing a json data in table format.Json contains different arrays and need to loop these arrays seperately.Everything working fine except the $index value.

Working Plunkr

Here i am looping each array in seperate tr.i need to get the index value updated like 1,2,3.. Any solutions??

2 Answers 2

3

If you necessarily needs to have them iterated as two different arrays you'll have to add the total number of members in the first array to the indexes for the second array, like this:

<!-- second tbody: -->
<tbody>
  <tr ng-repeat="prioritymembers in Records.priorityMembers">
    <td class="no" ng-bind="Records.stdMembers.length + $index+1"></td>
    <td class="name" ng-bind="prioritymembers.members.fname"></td>
  </tr>
</tbody>

Working plunker: http://plnkr.co/edit/1HiGoMuFAOTyOpD3SLoX?p=preview

Sign up to request clarification or add additional context in comments.

2 Comments

thanks for the reply..but in the case of 3 arrays it wil not work plnkr.co/edit/aI992wpMw5pw8oHvGcaj?p=preview
Got the answer.Just sum up first and second array length Thanks for the answer.
2

Interesting proble, I don't think there is a straitforward solution.

You could do

<tr ng-repeat="prioritymembers in Records.priorityMembers">
    <td class="no" ng-bind="$index + Records.stdMembers.length + 1"></td>
    ...
</tr>

Perhaps the cleaner solution would be to create a single array in the controller and iterate over that, instead of having 2 <body>s with separate iterations.

2 Comments

please check this link plnkr.co/edit/aI992wpMw5pw8oHvGcaj?p=preview it will not work for 3 arrays
Got the answer.Just sum up first and second array length Thanks for the answer.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.