[英]Returning response data from HTTP in Angular factory
.factory('Api', function($http) {
var API = "http://127.0.0.1:4567/";
return {
get: function(method) {
return $http.get(API + method).success(function(result) {
return result;
});
}
}
}
然后
console.log(Api.get("MAppData"));
返回
Object {then: function, success: function, error: function}
為什么不返回結果(響應數據)?
$http
返回一個promise,你需要鏈接.then()
來獲取這樣的數據:
Api.get("MAppData").then(function(response){
var data = response.data;
});
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.