私はいくつかのデータを返すWebサービスを持っています。私は角度サービスへのHTTPリクエストの呼び出しを移動したいコードの重複を防ぐために:、別の値で角度約束を作成する
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;
});
を何約束を返す最も簡単な方法はresponse.data.qwe.rty.xyz
の値をsuccessCallback
に直接送りますか?あなたがthen()
を呼び出した上で約束を返し$http.post('/path/', {})
def.getData().then(function (obj) {
scope.obj = obj;
});