1

normally, we can use ngRepeat="item in items" then use item.name to print out the name of the item. But what if the item has a dynamic structure which is only generated at run-time?

Say the item may have the following structure.

e.g.

data{
  field1: textfield;
  field2: integerfield;
  data:{
     field1:textfield;
     data:{
        field1:radiofield;
     }
     ...
  }
}

How can we print out all 'leaves' of this tree ?

wildcolor
  • 564
  • 1
  • 9
  • 23

1 Answers1

0

I agree that preparing the data in the controller before passing to ng-repeat is the simplest solution. Here is a simple JSBIN that pushes all of the properties of an object into a flat array and then prints the array to screen using ng-repeat.

Andrew Johnston
  • 1,109
  • 6
  • 11
  • Great recursive controller example. Thanks a lot. Only problem is that the "flattern function" loses the original tree structure. – wildcolor Nov 26 '14 at 09:39