nested ng-repeat to display a tree structure

1,003 views
Skip to first unread message

Safa Alai

unread,
Oct 15, 2012, 8:17:59 PM10/15/12
to ang...@googlegroups.com
I have a tree structure consisting of a collection of items, with each item having a collection of children, like so:

item 1
    child 1.1
    child 1.2
    child 1.3 
    .... etc
item 2
    child 2.1
    .... etc
item 3
    child 3.1
    .... etc
.... etc

I try displaying these items using ng-repeat as follows:

<ul>
   <li ng-repeat='item in items'><<item.title>>
       <ul>
             <li ng-repeat='child in item.children'><<child.title>></li>
       </ul>
   </li>
</ul>

The outer item list is expanded by Angular as expected, but the inner child list is not expanded and instead I simply see the comment:

<!-- ngRepeat: child in item.children -->

1.  Am I doing something wrong or is this simply a limitation of ngRepeat? 
2.  Is there a way I can get a nested list like this working in Angular?

Thx.

Anna Vester

unread,
Oct 15, 2012, 9:05:49 PM10/15/12
to ang...@googlegroups.com
Safa,

Take a look at this fiddle - http://jsfiddle.net/M3W52/ 

Hope this helps,

Anna

Anna Vester

unread,
Oct 15, 2012, 9:07:44 PM10/15/12
to ang...@googlegroups.com
Here is the updated version - http://jsfiddle.net/M3W52/1/
Reply all
Reply to author
Forward
0 new messages