Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

how do i refer to the $index of the parent loop inside a nested ng-repeat?

I am nesting ng-repeat in my App.

In that I'm trying to refer to the $index of parent loop

.div(ng-repeat= item in items)
  p(ng-repeat= detail in item.details)
    a(href='#') // $$ index ?

how do i refer to the $index of the parent loop (ie. $index of item) inside a nested ng-repeat?

(the above code is in jade)

like image 839
Sangram Singh Avatar asked Oct 05 '13 10:10

Sangram Singh


People also ask

How do I get the index of an element in NG-repeat?

Note: The $index variable is used to get the Index of the Row created by ng-repeat directive. Each row of the HTML Table consists of a Button which has been assigned ng-click directive. The $index variable is passed as parameter to the GetRowIndex function.

Where is the last element in NG-repeat?

You can use $last variable within ng-repeat directive. Take a look at doc. Where computeCssClass is function of controller which takes sole argument and returns 'last' or null .

How do you use two ng-repeat in a table?

You can nest two ng-repeat together in order to create a more complex table. The first ng-repeat in the tr tag will create the rows and the second one in the td tag will create one column per element in the collection.

Does ng-repeat create a new scope?

Directives that Create Scopes In most cases, directives and scopes interact but do not create new instances of scope. However, some directives, such as ng-controller and ng-repeat, create new child scopes and attach the child scope to the corresponding DOM element.


1 Answers

Use scope' parent' $index: $parent.$index. Something like (just guess , i don't know much about Jade):

.div(ng-repeat= item in items)
  p(ng-repeat= detail in item.details)
    a(ng-href='#/{{$parent.$index}}') 

Working example (not Jade): http://jsfiddle.net/Ysxsx/

like image 78
Ivan Chernykh Avatar answered Oct 13 '22 10:10

Ivan Chernykh