5dpe2w
Last Updated: February 25, 2016
·
9.745K
· gus
8ac27b57a20a836d2d3edf0cace6c743

Execute function when ngRepeat done

ngRepeat is one of Angular's most powerful directives, sometimes you might find yourself wanting to update the DOM or execute a function after the directive has finished its job.

We can use a custom directive and $destroy() to accomplish this.

var app = angular.module("app", []);

app.directive('repeatDone', function() {
  return function(scope, element, attrs) {
    element.bind('$destroy', function(event) {
      if (scope.$last) {
        scope.$eval(attrs.repeatDone);
      }
    });
  }
});

Then we can use it along with ngRepeat in the following fashion.

<div ng-repeat="item in model.items" repeat-done="foo()"></div>
Say Thanks
Respond