index of outer loop when nesting ng:repeat

7,871 views
Skip to first unread message

Shishir Ramam

unread,
May 12, 2011, 4:47:11 PM5/12/11
to ang...@googlegroups.com
I am trying to render a small grid with two nested loops. 
Each element of the grid can be rendered in one of many styles (5 in my case). 
The intent is to use ng:switch to discriminate. I need the row and col index to be able to do this. 

Can't seem to figure how to get the row index in the segment below. (test file attached). 

            <div ng:repeat='row in elems' class='row_{{$index}}'>
                <div ng:repeat='col in row' class='panel col_{{$index}}'>
                    <ng:switch on='orient(elems.$indexOf(row), $index)'>
                        <div ng:switch-when='0'>0</div>
                        <div ng:switch-when='1'>1</div> 
                        <div ng:switch-when='2'>2</div> 
                        <div ng:switch-when='3'>3</div> 
                        <div ng:switch-default>default</div> 
                    </ng:switch>
                </div>
            </div>


thanks for all help,
-shishir

test.html

Mårten Dolk

unread,
May 12, 2011, 5:04:02 PM5/12/11
to ang...@googlegroups.com
ng:repeat creates a new child scope and I think you can access the
parent via $parent

<ng:switch on='orient($parent.$index, $index)'>

/mårten

2011/5/12 Shishir Ramam <sra...@gmail.com>:

> --
> You received this message because you are subscribed to the Google Groups
> "angular" group.
> To post to this group, send email to ang...@googlegroups.com.
> To unsubscribe from this group, send email to
> angular+u...@googlegroups.com.
> For more options, visit this group at
> http://groups.google.com/group/angular?hl=en.
>

Shishir Ramam

unread,
May 12, 2011, 5:26:27 PM5/12/11
to ang...@googlegroups.com
Thanks Mårten!
Didn't see it till I fixed this - but the orient function seems to be called three times.  Any clues as to why? 

For the moment, the computation within orient is rather simple and I don't expect a performance hit. 
But this smells like a bug. 

-shishir

--
Imagine there were no hypothetical situations.
Reply all
Reply to author
Forward
0 new messages