Last Updated: February 25, 2016
· gus

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) {

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

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