Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Irregular repetitions in table using JavaScript and Angular.JS

I would like to iterate over some data like this:

<table>
    <tr ng-repeat="(k,val) in items">
        <td>{{k}} {{val.style}}</td>
        <td ng-repeat="(k2, item) in val.items">{{item.title}}</td>
        <td>{{item.ingredients}}</td> <-- (a)
        <td>{{item.moreInfo}}</td> <-- (b)
    </tr>
</table>

(a) and (b) [and c, d, e...] would also use the object "item in val.items", but {{item.ingredients}} is not a valid expression there, because it is out of the <td> with the object that I want to use to create more columns.

Example of what it would look like: http://jsfiddle.net/yj7xopgy/

Is there any way to do something like that?

like image 537
Sergio Avatar asked Aug 16 '15 23:08

Sergio


Video Answer


1 Answers

Use ng-repeat-start and ng-repeat-end.

<td ng-repeat-start="(k2, item) in val.items">{{item.title}}</td>
<td>{{item.ingredients}}</td> 
<td ng-repeat-end>{{item.moreInfo}}</td>

Updated Fiddle

like image 77
Kirill Slatin Avatar answered Oct 19 '22 14:10

Kirill Slatin