Ng-repeat does not work as expected

Below the object should generate table rows for parent and child objects under the same table (like siblings). as it may be, I used ng-repeat-start but not used. I need this for equal alignments.

[ {'name':'parent1','children':[{'name':'child1'},{'name':'child2'}]}, {'name':'parent2','children':[{'name':'child1'},{'name':'child2'}]} ...... ] <table> <tr ng-repeat="parent in obj"> <td>{{parent.name}}</td> </tr> <tr ng-repeat="child in parent.children"> <td>{{child.name}}</td> </tr> ........... 

The table should be generated as shown below:

 <table> <tr> <td>Parent1</td> </tr> <tr> <td>child1</td> </tr> <tr> <td>child2</td> </tr> <tr> <td>Parent2</td> </tr> <tr> <td>child1</td> </tr> <tr> <td>child2</td> </tr> ...... </table> 
0
angularjs angularjs-ng-repeat
source share
2 answers

You can try

 <table> <tr ng-repeat-start="parent in obj"> <td>{{parent.name}}</td> </tr> <tr ng-repeat="child in parent.children"> <td>{{child.name}}</td> </tr> <tr ng-repeat-end=""> <tr/> </table> 
+2
source share

Everything is alright because this code

 <tr ng-repeat="child in parent.children"> <td>{{child.name}}</td> </tr> 

leaves this area

 <tr ng-repeat="parent in obj"> <td>{{parent.name}}</td> </tr> 

if you want to achieve what you want, you can create a flat array like this

 [ {'name':'parent1'}, {'name':'children1'}, ... ... ] 

and iterate over it

+1
source share

All Articles