Calling a function when ng-repeat has finished

前端 未结 10 1655
面向向阳花
面向向阳花 2020-11-22 02:28

What I am trying to implement is basically a \"on ng repeat finished rendering\" handler. I am able to detect when it is done but I can\'t figure out how to trigger a functi

10条回答
  •  你的背包
    2020-11-22 03:07

    The other solutions will work fine on initial page load, but calling $timeout from the controller is the only way to ensure that your function is called when the model changes. Here is a working fiddle that uses $timeout. For your example it would be:

    .controller('myC', function ($scope, $timeout) {
    $scope.$watch("ta", function (newValue, oldValue) {
        $timeout(function () {
           test();
        });
    });
    

    ngRepeat will only evaluate a directive when the row content is new, so if you remove items from your list, onFinishRender will not fire. For example, try entering filter values in these fiddles emit.

提交回复
热议问题