I am able to fire an event after ng-repeat finishes the first time. However, I am unable to make the event fire after every ng-repeat consistently. It would appear that the event doesn't occur if the ng-repeat is a subset of the previous ng-repeat data.
I found this answer which provides a hacky solution to this problem using a filter. Does anyone know of a better way to make an event fire after every ng-repeat completion?
var app = angular.module('appname', []);
app.controller('Ctrl', function($scope) {
$scope.data = [1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15, 16, 17, 18, 19, 20];
$scope.limit = 11;
$scope.$on('ngRepeatFinished', function(ngRepeatFinishedEvent){
alert('Repeat Finished!');
});
});
app.directive('onFinishRender', function(){
return function(scope, element, attr){
if(scope.$last){
scope.$emit('ngRepeatFinished');
}
}
});
<script src="https://ajax.googleapis.com/ajax/libs/angularjs/1.2.23/angular.min.js"></script>
<div ng-app="appname" ng-controller="Ctrl">
<select ng-model="limit">
<option ng-repeat="o in data"value="{{o}}">{{o}}</option>
</select>
<ul>
<li ng-repeat="x in data | limitTo: limit" on-finish-render>{{x}}</li>
</ul>
</div>