I have a web service which returns some data. To prevent code duplication I want to move http request call to angular service:
angular.module('abc', [])
.factory('def', function () {
return {
getData: function () {
return $http.post('/path/', {});
}
};
});
All is good, but necessary data is inside complicated object, and I have to write every time:
def.getData().then(function (response) {
scope.obj = response.data.qwe.rty.xyz;
});
What is the easiest way to return promise, which will send value of response.data.qwe.rty.xyz directly to successCallback? And I can write like this:
def.getData().then(function (obj) {
scope.obj = obj;
});