I am trying to resolve a promise from angular $resource save.
The docs specify that I can access the raw $http promise via the $promise property on the object returned as follows:
var User = $resource('/user/:userId', {userId:'@id'});
User.get({userId:123})
.$promise.then(function(user) {
$scope.user = user;
});
This works for the get, however, when I attempt to access the promise on the save, I get an error. What am I doing wrong and why would resolving the save work differently than resolving the get?
Note: The POST request is working and I can see the correct response being returned from the server in the browser's Network tool. I just can't access the results in the promise.
In My Service
var itemResource = $resource('/api/myUrl/:id/:action', { id: '@id', action: '@action' });
function getItem(id) {
return itemResource.get({ id: id });
}
function saveItem(item) {
return itemResource.save(item);
}
In My Controller
var getResult = itemService.getItem({ id: 1560 });
getResult.$promise.then(function (itemDef) { // THIS WORKS!!!
console.log(itemDef);
});
var saveResult = itemService.saveItem(item);
saveResult.$promise.then(function (itemDef) { // Cannot read property 'then' of undefined
console.log(itemDef);
});