Skip to content

Instantly share code, notes, and snippets.

@Bolza
Created October 15, 2015 10:14
Show Gist options
  • Save Bolza/eb2bf87cfcd2ff0bcb7c to your computer and use it in GitHub Desktop.
Save Bolza/eb2bf87cfcd2ff0bcb7c to your computer and use it in GitHub Desktop.
Wraps ng-repeat
app.controller('MainCtrl', function($scope) {
$scope.numbers=[1,2,3,4,5,6];
});
app.directive('myRepeat', function($compile){
return {
//High priority means it will execute first
priority: 5000,
//Terminal prevents compilation of any other directive on first pass
terminal: true,
compile: function(element, attrs){
//Add ng-repeat to the dom
attrs.$set('ngRepeat', attrs.myRepeat);
//Now that we added ng-repeat to the element, proceed with compilation
//but skip directives with priority 5000 or above to avoid infinite
//recursion (we don't want to compile ourselves again)
var compiled = $compile(element, null, 5000);
return function(scope){
//When linking just delegate to the link function returned by the new
//compile
compiled(scope);
}
}
}
})
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment