Post ngRepeat Code

all those questions,
How to run function after ngRepeat is done
Calling a function when ng-repeat has finished
ng-repeat finish event

all the answers in stackoverflow goes around
<ul>
    <li ng-repeat="item in items" 
        ng-init="$last ? doSomething() : angular.noop()">{{item}}</li>
</ul>
which are nice and are a real solution, while each answer eventually give the same solution a bit more generic.

one blog puts it quite better, while also enabling to choose the digest cycle stage, with the exception that you better use $parse instead of $eval:
http://www.bennadel.com/blog/2592-hooking-into-the-complete-event-of-an-ngrepeat-loop-in-angularjs.htm

but in the end we usually just do some simple JS or JQ code or plugin, and i think that the real solution here is a simple 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

Comments

Popular posts from this blog

c# Service Play Sound with NAudio example by Moshe

SOLVED The item could not be indexed successfully because the item failed in the indexing subsystem

JS/JQ simulate Enter event