更新:02/12/2015 正如在评论中提到的,这是一个由Angular模块修改对象的问题。如下所述,我可以使用toJSON
进行追踪。角度承诺从JSON API返回不正确的数据
我最近遇到了一个非常难以理解的问题。我有一项服务,即通过get
请求从api获取请求数据。在Chrome开发人员工具中查看网络面板时,api会返回正确的结果,但它们不会显示在角度请求的响应中。
你可以注意到内容部分缺少项目。和角码:
角码
function getPhotos(){
return $http.get('/photo')
.then(getPhotosComplete)
.catch(function(err){
//handle errors
});
function getPhotosComplete(res){
//Showing incorrect response here
console.log("getPhotosComplete", res);
return res.data;
}
}
从API { url: "https://dev.amazonaws.com/060a2a5f-8bb7-4ffa-aa7d-e715439271a3.jpg", archive_name: "140809", seedcount: 0, viewcount: 0, live: true, current: false, next: false, createdAt: "2015-02-10T17:48:41.505Z", updatedAt: "2015-02-12T04:11:02.239Z", content: [ "Balloon", "Apartment", "Testing", "Testing 2", "Party", "Inez" ], id: "54da44790eb10b0f00b453a1" }
在服务范围角/ res.data { url: "https://dev.amazonaws.com/060a2a5f-8bb7-4ffa-aa7d-e715439271a3.jpg", seedcount: 0, viewcount: 0, live: true, current: false, next: false, createdAt: "2015-02-10T17:48:41.505Z", updatedAt: "2015-02-12T04:11:02.239Z", content: Array[3] 0: "Balloon", 1: "Apartment", 2: "Party" ]
如果您使用的是非缩小的Angular,则可以调试到Angular的代码来查看Angular如何转换您的响应。 AFAIK,Angular会尝试将您的响应转换为JSON对象。也许在那里出了问题。 – Rebornix 2015-02-12 04:35:55
你确定吗?尝试使用JSON.stringify进行日志记录,以确保它不仅仅是一个显示工件。 'Array [3] 0:“Balloon”,1:“Apartment”,2:“Party”]看起来很可疑,因为它甚至不是JSON – 2015-02-12 04:39:03
@JuanMendes - 我相信,它只是返回的对象安慰。我也使用batarang并登录很多地方。 – jeffreynolte 2015-02-12 04:41:34