Every solution posted which refers to detecting when ng-repeat finishes leans on the scope.$last value, like this:
angular.module('fooApp')
.directive('onLastRepeat', function () {
return function (scope, element, attrs) {
if (scope.$last) {
setTimeout(function () {
scope.$emit('onRepeatLast', element, attrs);
}, 1);
}
};
})
The problem is that this solution only works if you append to the end of the list. If you insert data in the middle, scope.$last will always be false and you have no idea when angularjs has finished renedering your newly bound rows. Does anyone have a solution which work regardless of where ng-repeat renders the data?
example:
html:
<button ng-click="addToList()"></button>
<table>
<tbody>
<tr ng-repeat="foo in list" on-last-repeat><td><span>{{foo}}</span></td></tr>
</tbody>
</table>
controller code:
$scope.addToList = function() {
$scope.list.splice(1, 0, 4);
}
$scope.list = [1, 2, 3];
if you click the button in an example with the above code $scope.last is false in the directive which is supposed to trigger when rendering is done.