I currently have a factory that submits a POST request with data.
Here is the factory:
app.factory('Quotes', ['$http',function($http, $q) {
var urlBase = 'http://test-url.com';
var Quotes = {};
Quotes.createQuote = function (data) {
return $http.post(urlBase + '/', data)
};
return Quotes;
}]);
I have an array of objects, and each object needs to be submitted separately in it's own POST request. I have this controller..
I am passing $scope.array into the saveQuote() function.
$scope.saveQuote = function(data){
$rootScope.loading = true;
angular.forEach(data, function(quote){
Quotes.createQuote(quote)
.success(function (data, status, headers, config) {
$rootScope.loading = false;
$rootScope.status = {header: "Success", message: "Success", type: "success"};
})
.error(function (data, status, headers, config) {
$rootScope.status = {header: "Error", message: data};
});
});
}
How do i create a function when ALL of the post requests have completed?
UPDATE:
Also, how do i output each error response for each POST? It seems the answer below outputs only one of them?