angularjs - Accessing Value from JavaScript Callback -


i'm trying push value anglular.js service callback array. appreciated. thanks.

$scope.checkaddondependencies = function(addon) {     var addons = new array();     var arr = filterfilter($scope.addons, {checked: true});     var length = arr.length, element = null;      (var = 0; < length; i++) {         element = arr[i]['addoncode'];         addons.push(element); //works fine          myservice.addon_dependencies(arr[i]['addoncode']).then(function(dependency) {              addons.push(dependency); //not working         });      }      console.log(addons);     } 

basically need handle value in callback this:

myservice.addon_dependencies(arr[i]['addoncode']).then(function(dependency) {     addons.push(dependency);  }); 

update

since callback of function then() async, there no guarantee console.log(addons) shows in code order.


Comments

Popular posts from this blog

Issues changing the value of an element in an array in matlab -

php - MySQLi binding parameters in a prepared statement doesn't work unless inserted after "WHERE" -

vb.net - Alternative to the T-SQL AS keyword -