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>
Written by Gus Bonfant
Related protips
Have a fresh tip? Share with Coderwall community!
Post
Post a tip
Best
#Events
Authors
Sponsored by #native_company# — Learn More
#native_title#
#native_desc#