aztack / AngularJS-translation

Chinese translation of book AngularJS by Brad Green & Shyam Sesbadri
49 stars 15 forks source link

HowTo - Call a function when ng-repeat has finished? #6

Open aztack opened 11 years ago

aztack commented 11 years ago

Call a function when ng-repeat has finished

var module = angular.module('testApp', [])
    .directive('onFinishRender', function ($timeout) {
    return {
        restrict: 'A',
        link: function (scope, element, attr) {
            if (scope.$last === true) {
                $timeout(function () {
                    //do something with the element
                });
            }
        }
    }
});
<ul>
  <li ng-repeat="item in list" on-finish-render>{{item.name}}</li>
</ul>