The CreatorCon Call for Content is officially open! Get started here.

How to use ng-repeat and ng-if with array within an array

davilu
Mega Sage

Hi Everyone,

I have an array that has another array within it.   This is what the structure looks like in the console:

find_real_file.png

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!

2 REPLIES 2

Brian Dailey1
Kilo Sage

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


xiaix
Tera Guru

<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>