ng-repeat finish event

前端 未结 15 2837
盖世英雄少女心
盖世英雄少女心 2020-11-22 02:15

I want to call some jQuery function targeting div with table. That table is populated with ng-repeat.

When I call it on

$(document).r         


        
15条回答
  •  野性不改
    2020-11-22 02:47

    i would like to add another answer, since the preceding answers takes it that the code needed to run after the ngRepeat is done is an angular code, which in that case all answers above give a great and simple solution, some more generic than others, and in case its important the digest life cycle stage you can take a look at Ben Nadel's blog about it, with the exception of using $parse instead of $eval.

    but in my experience, as the OP states, its usually running some JQuery plugins or methods on the finnaly compiled DOM, which in that case i found that the most simple solution is to create a directive with a setTimeout, since the setTimeout function gets pushed to the end of the queue of the browser, its always right after everything is done in angular, usually ngReapet which continues after its parents postLinking function

    angular.module('myApp', [])
    .directive('pluginNameOrWhatever', function() {
      return function(scope, element, attrs) {        
        setTimeout(function doWork(){
          //jquery code and plugins
        }, 0);        
      };
    });
    

    for whoever wondering that in that case why not to use $timeout, its that it causes another digest cycle that is completely unnecessary

提交回复
热议问题