This question has been partly addressed here: Angular.js ng-repeat across multiple tr's
However that is just a work-around really, it doesn't actually address the core issue, which is: how can one use ng-repeat across multiple elements without a wrapper?
For example, jquery.accordion requires you to repeat an h3 and div element, how could one do this with ng-repeat?
We now have a proper support for this, please see:
AngularJs Commmit
with this change you can now do:
<table>
<tr ng-repeat-start="item in list">
<td>I get repeated</td>
</tr>
<tr ng-repeat-end>
<td>I also get repeated</td>
</tr>
</table>
To answer Andre's question above on more than 2 levels of ng-repeat in a table, you can use multiple ng-repeat-start to accomplish this.
<tr ng-repeat-start="items in list">
<td>{{items.title}}</td>
</tr>
<tr ng-repeat-start="item in items">
<td>{{item.subtitle}}</td>
</tr>
<tr ng-repeat-end ng-repeat="value in item.values">
<td>{{value.col1}}</td>
<td>{{value.col2}}</td>
</tr>
<tr ng-repeat-end></tr>
Here is a plunker example
UPDATE: This answer is outdated. Please see @IgorMinar answer and use standard ng-repeat-start
and ng-repeat-end
directives.
There are two options:
First option is to create directive that will render several tags and replace source tag (jsfiddle)
angular.module('components').directive('multi', function ($compile) { return { restrict: 'A', scope : { first : '=', last : '=', }, terminal:true, link: function (scope, element, attrs) { var tmpl = '', arr = [0,1,2,3] // this is instead of your repeater for (var i in arr) { tmpl +='
element.replaceWith(newElement);
will replace wrapper tag with what you need. also you can have loop in your directive and add as many tags as you need into tmpl.
Success story sharing