Saturday 15 January 2011

javascript - angularjs: detect when ng-repeat finishes when rows added in the middle -



javascript - angularjs: detect when ng-repeat finishes when rows added in the middle -

every solution posted refers detecting when ng-repeat finishes leans on scope.$last value, this:

angular.module('fooapp') .directive('onlastrepeat', function () { homecoming function (scope, element, attrs) { if (scope.$last) { settimeout(function () { scope.$emit('onrepeatlast', element, attrs); }, 1); } }; })

the problem solution works if append end of list. if insert info in middle, scope.$last false , have no thought when angularjs has finished renedering newly bound rows. have solution work regardless of ng-repeat renders 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 click button in illustration above code $scope.last false in directive supposed trigger when rendering done.

could utilize this?

angular.module('fooapp') .directive('onlastrepeat', function () { homecoming function (scope, element, attrs) { if (scope.$middle) { settimeout(function () { scope.$emit('onrepeatmiddle', element, attrs); }, 1); } if (scope.$last) { settimeout(function () { scope.$emit('onrepeatlast', element, attrs); }, 1); } }; })

javascript angularjs

No comments:

Post a Comment