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
Post a Comment