我尝试使用Restangular来处理对我的restful API的调用。
这是我的代码:
var baseStories = Restangular.all('stories/all');
baseStories.getList().then(function (stories) {
console.log(stories);
})
console.log显示完整的restangularized数组,而不是我期望的故事数组。
我使用文档中的RestangularProvider.addResponseInterceptor来解包响应数据。
有谁知道我错过了什么?
修改 下面是上面代码中console.log输出的屏幕截图。我看到两个故事(这是正确的)和一堆Restangular方法。是否有可能只获得故事?
答案 0 :(得分:4)
实际上addResponseInterceptor
必须返回resangularized元素。它写在文档中:
https://github.com/mgonto/restangular#addresponseinterceptor
为了获得干净的回复,您必须在plain()
元素上调用response
方法:
var baseStories = Restangular.all('stories/all');
baseStories.getList().then(function (response) {
$scope.stories = response.plain();
})