javascript - AngularJS promises don't execute in order -
javascript - AngularJS promises don't execute in order -
i can’t head around of promises. work fine in instances of app, in never work.
in controller, have next command:
myfactory.redrawcategories() .then(myfactory.redrawtasks()); the redrawtasks function called instantly, without waiting redrawcategories finish.
the functions within mill this
redrawtasks: function(){ var defer = $q.defer(); db.getalldocs("task_").then(function(res) { angular.foreach(res, function(value){ value = value.doc; tasks[value.category].push(value); }); angular.foreach(tasks, function(taskarray, cat){ // code }); defer.resolve(1); }); homecoming defer.promise; }, the other 1 like
redrawcategories: function(){ var deferred = $q.defer(); db.getalldocs("category_").then(function(res) { var categoryarray = []; angular.foreach(res, function(value){ categoryarray.push(value.doc); }); deferred.resolve("done"); }); homecoming deferred.promise; }, some of unimortant code has been removed improve overview.
no thought how it. i've tried putting resolve() function in front end of homecoming doesn't work either.
i've read have wrap things in $scope.$apply, in case $rootscope.$apply it's in mill outside of controller scope, doesn't alter either, besides haven't grasped when "outside of angular" describe that.
i've read lot of examples , tutorials, don't see forest trees anymore.
any help appreciated lot. i'm stuck :/ thanks
.then expects function reference.
myfactory.redrawcategories() .then(myfactory.redrawtasks()); should be
myfactory.redrawcategories() .then(myfactory.redrawtasks); when have () function executed , .then passed whatever returned.
as noted in comments, if you're relying on this in redrawtasks you'd do
myfactory.redrawcategories() .then(function() { homecoming myfactory.redrawtasks(); }); javascript angularjs promise
Comments
Post a Comment