Created
July 11, 2013 23:57
-
-
Save agrublev/5980333 to your computer and use it in GitHub Desktop.
AngularJS using $q promises with $resource before Version 1.2 of Angular comes out
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
var errors = []; | |
var returnData = []; | |
angular.forEach(array,function(val,ind){ | |
var tmpDef = $q.defer(); | |
errors.push(tmpDef.promise); | |
some$resource.save({someId: val.id},'',function(data){ | |
// success resolve promise with data returned | |
tmpDef.resolve('success'); | |
returnData.push(data); | |
},function(data){ | |
// error resolve promise with data returned | |
tmpDef.reject('error'); | |
returnData.push(data); | |
}); | |
}); | |
$q.all(errors).then(function(data){ | |
// All $resource calls are resolved this is the final data | |
console.log(returnData,data); | |
}); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment