Yes, you can do this, but it's not quite as easy as how you've written it
I assume that each put
will give you a promise (I have never used restangular). What you want to do is create a list of promises and then use $q.all
.
NOTE be sure to inject $q
into your controller/service.
// Initialise an array.
var promises = [];
angular.foreach(objects, function(data) {
// Add the `put` to the array of promises we need to complete.
promises.push(restangular.one('user', user.id).one(object).put());
});
// combine all the promises into one single one that resolves when
// they are all complete:
$q.all(promises)
// When all are complete:
.then( function(resultArray){
// An array of results from the promises is passed
var resultFromFirstPromise = resultArray[0];
// Do whatever you want here.
angular.updateInfo('user');
});