I want to create a custom repeater directive and pass the expression to ng-repeat inside the directive template.
The reason for this is to provide a cleaner interface in html, since I also include other under-the-hood directives.
http://jsfiddle.net/DeanIconWeb/Cg9RC/1/
Here is my html template:
<tr custom-repeater="person in people"> <td>{{person.name}}</td> <td>{{person.gender}}</td> <td>{{person.age}}</td> </tr>
Here is my directive:
app.directive("customRepeater", function(){ return { priority : 2000, restrict: 'A', replace : true, transclude : true, scope : { ngRepeatExp : "@customRepeater" }, template : "<tr ng-repeat='{{ngRepeatExp}}' ng-class-even=\"'even'\" ng-transclude></tr>" } });
While trying to do this work, I continued to get the error "The template must have one root element."
In the end, I did the following, but that is not what I really want.
<tr ng-repeat="person in people" custom-repeater> <td>{{person.name}}</td> <td>{{person.gender}}</td> <td>{{person.age}}</td> </tr>
Directive
app.directive("customRepeater", function($compile){ return { priority : 2000,
source share