我想将$ http调用的结果投影到另一个模型中,以使投影成为服务调用的全局。
换句话说,我从http / api调用得到的结果并没有使用我想要的确切模型。
如何在我的服务类中进行此投影?
angular.module('openart')
.factory('BritishLibraryApi', ['$http', function ($http) {
return {
getPage:function(page){
return $http({method:"GET",url:'/api/british-library/'+page})
.success(function(data){
//would like to do something here like
return data.results.map(function(i){
//project i into another model here
return {
};
});
});
}
};
}]);
答案 0 :(得分:0)
如果您创建自己的承诺并解决映射数据
angular.module('openart')
.factory('BritishLibraryApi', ['$http','$q', function ($http,$q) {
return {
getPage:function(page){
var defer=$q.defer();
$http({method:"GET",url:'/api/british-library/'+page})
.success(function(data){
//would like to do something here like
defer.resolve(data.results.map(function(i){
//project i into another model here
return {
};
}));
});
return defer.promise;
}
};
}]);