Calling .success
returns the same deferred object that it was called on. It does not create a new object. All it does is register a success
callback on the deferred.
You can use the new reference, or just keep the old reference:
service.getItemByID = function(id) {
var hp = $http({method: "GET", url: "service/open/item/id",
headers: {"token": $rootScope.user.token},
params: {"id": id}});
hp.success(
function(data, status, headers, config) {
data.x = "test"; //TODO: add full manipulation
alert("success");
return hp;
});
return hp;
};
If you want to, you could just chain them all, and return the deferred object directly:
service.getItemByID = function(id) {
return $http({
method: "GET",
url: "service/open/item/id",
headers: {"token": $rootScope.user.token},
params: {"id": id}
})
.success(function(data, status, headers, config) {
data.x = "test";
alert("success");
});
};
与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…