【发布时间】:2017-11-07 21:54:13
【问题描述】:
我有一个返回一些数据的网络服务。为防止代码重复,我想将 http 请求调用移至 Angular 服务:
angular.module('abc', [])
.factory('def', function () {
return {
getData: function () {
return $http.post('/path/', {});
}
};
});
一切都很好,但必要的数据在复杂的对象中,我每次都要写:
def.getData().then(function (response) {
scope.obj = response.data.qwe.rty.xyz;
});
返回promise的最简单方法是什么,它将response.data.qwe.rty.xyz的值直接发送到successCallback?我可以这样写:
def.getData().then(function (obj) {
scope.obj = obj;
});
【问题讨论】:
标签: angularjs promise angular-promise