I am using $resource
to retrieve data from the server using query.
The server returns an array of objects, which I store in stuklijst.
I can send the (
You can send an array of objects by re-defining your resource's save
function to specify isArray=true
like so:
stukModule.factory('Stuklijsten', ['$resource', function ($resource) {
return $resource(
'rest/stuklijsten/:stuklijstID',
{},
{
save: {
method: 'POST',
isArray: true
}
}
);
}]);
Then, in your controller, you can assemble the list and save all in one http request (less chatty API):
$scope.saveStuklijst = function(lijst) {
var some_list = [];
for(var i = 0; i < lijst.length; i++) {
lijst[i].RowID = i
f = new Stuklijsten(lijst[i]);
some_list.push({stuklijstID: $routeParams.stuklijstID});
};
Stuklijsten.save(some_list);
If you wanted to still be able to POST single objects, you could use the same concept to create a saveBulk
function to preserve the original save
for the single objects.