1

I've a serious problem with iterating an array (list) in AngularJS.
The structure of the array is -> items{ var1, var2, array2[var3, var4] }.
I want to display this array on a HTML page in a table with ng-repeat as follows:

<tr ng-repeat="item in items">
   <td >{{item.var1}}</td>
   <td >{{item.var2}}</td>
   <td ng-repeat="...">###</td>
</tr>

and in the place of "###" I need to display array2's variables after the right ng-repeat dercription, but I don't know the right syntax for this case. I have tried many solutions, but none of them was helpful.

Thanks for answers! :-)

1
  • you would just do < td ng-repeat="subitem in item.array2">{{subitem}}< /td > Commented Nov 8, 2014 at 21:19

4 Answers 4

1

Nested ng-repeats can lead to performance problems. If the inner array is strings or numbers, consider using something like:

  <div ng-repeat="inner in outer">
         {{inner.join(',')}}
<div>
Sign up to request clarification or add additional context in comments.

Comments

1

use this code, here i refers to each nested array item in item.array2

      <tr ng-repeat="item in items">
    <td >{{item.var1}}</td>
   <td >{{item.var2}}</td>
   <td ng-repeat="i in item.array2">{{i}}</td>
</tr>

Comments

1

You should just iterate in item.array2, as you did in the first ng-repeat, something like:

<tr ng-repeat="item in items">
    <td >{{item.var1}}</td>
    <td >{{item.var2}}</td>
    <td ng-repeat="item_ in item.array2">
         {{item_}}
    </td>
</tr>

I have not tried, but it should work.

Comments

0

You had it right, it's as easy as nesting the ng-repeat, just use the first ng-repeated item's array property as the model for the nested one:

Try this, as I mentioned in my comment:

< td ng-repeat="subitem in item.array2">{{subitem}}< /td >

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.