Last Updated: February 25, 2016
·
27.28K
· kelion

ng-repeat without parent element

For ng-repeat directive in angular.js we should provide element, that will be repeated. But sometimes we want to have several DOM elements for each item, without any wrapper.

In my case it was two elements for each item: left is static and right to be sortable:
Picture

For simple ng-repeat we can do it only with wrapper for each item:

<div ng-repeat="item in items">
  <div>{{item.word}}</div>
  <div>{{item.definition}}</div>
</div>

Since version 1.2 in angular js we have new directives — ng-repeat-start and ng-repeat-end and now we can replace our code to:

<div ng-repeat-start="item in items">{{item.word}}</div>
<div ng-repeat-end>{{item.definition}}</div>

Use it!