How to use ng-repeat and ng-if with array within an array
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
01-16-2018 03:48 PM
Hi Everyone,
I have an array that has another array within it. This is what the structure looks like in the console:
I know how to access the stage array via ng-repeat and ng-if, but how am I able to access the task array within the stage array? When I used ng-repeat to generate the workflow stages, I simply did ng-repeat="item in c.stage track by $index" and it worked perfectly. However below that I want to have a div that displays something if incompleteCounter is greater than 0 and something else when incompleteCounter is equal to 0. In this case, how would I write an ng-if with these nested arrays?
I've tried ng-if="item.task.incompleteCounter>0", but that obviously didn't work. What is the correct syntax for this? Thanks!

- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
01-16-2018 07:13 PM
Hi David,
Because task is also an array, you might want to try another (e.g., nested) ng-repeat to iterate through all tasks in item.task, and then within that loop have your ng-if check the value of task.incompleteCounter.
What it comes down to is that "item.task" is not specific, it's an array... you need to select one task from the array to do your comparison.
Thanks,
-Brian

- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
01-17-2018 04:22 AM
<div ng-repeat="item in container" ng-init="parentIndex = $index">
<div ng-repeat="groceries in basket">
{{$index}} <!-- inner $index -->
{{$parent.$index}} <!-- parent $index -->
{{parentIndex}} <!-- also parent $index -->
</div>
</div>