I had an angular Service with a function:
service.getItemByID = function(id) {
var hp = $http({method: "GET", url: "service/open/item/id",
headers: {"token": $rootScope.user.token},
params: {"id": id}});
return hp;
};
I need to manipulate the returned values before sending them on and I want to keep the HttpPromise structure intact since my controller code is written to expect the success and failure functions of the HttpPromise to be present.
I have rewritten the service to look like this:
service.getItemByID = function(id) {
var hp = $http({method: "GET", url: "service/open/item/id",
headers: {"token": $rootScope.user.token},
params: {"id": id}});
var newHP = hp.success(
function(data, status, headers, config) {
data.x = "test"; //TODO: add full manipulation
alert("success");
return hp;
});
return newHP;
};
This code works and it work regardless of whether I return hp or newHP. My question is: Is this a proper form of HttpPromise chaining?
See Question&Answers more detail:os