【发布时间】:2016-07-21 19:21:21
【问题描述】:
如果你想创建一个只需要通过 http 调用一个 API 的服务,我仍然无法理解使用 $q 服务的作用,(它到底会添加什么),在这种情况下我不知道为什么我不应该只执行以下操作(不使用 $q):
this.getMovie = function(movie) {
return $http.get('/api/v1/movies/' + movie)
.then(
function(response) {
return {
title: response.data.title,
cost: response.data.price
});
},
function(httpError) {
// translate the error
throw httpError.status + " : " +
httpError.data;
});
};
【问题讨论】:
标签: angularjs angular-promise angularjs-http