Restangular getList() 返回空数组 [英] Restangular getList() returning empty array

查看:72
本文介绍了Restangular getList() 返回空数组的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在尝试使用 Restangular 从 Angular JS 调用 Java REST API.我能够在网络选项卡中看到正确的响应,但是当我尝试在控制台中记录相同内容或在 html 文件中显示时,响应对象具有空数组.

I am trying to invoke a Java REST API from Angular JS using Restangular. I am able to see proper response in the network tab but the response object is having empty array while i try to log the same in console or display in the html file.

class TestClass {
/*@ngInject*/
constructor($log, Restangular) {
this.Restangular = Restangular;
this.$log = $log;
this.test = "somethings";
var me = this;
 this.Restangular.all('api/people/').getList().then(response => {
    this.test = response;
    console.log(response);
 });
}

我在 app.js 文件中定义了以下配置

I have the following configurations defined in my app.js file

 .config(/*@ngInject*/function(RestangularProvider) {
  RestangularProvider.setBaseUrl('http://localhost:8080/');
RestangularProvider.setFullResponse(true);
RestangularProvider.addResponseInterceptor(function(data, operation, what, url, response, deferred) {
    var extractedData;
    if (operation === "getList") {
      extractedData = data.result;
    } else {
      extractedData = data;
    }
    return extractedData;
  });
})

控制台

网络

推荐答案

你应该确保来自 Restangular getList() 的响应在 data.result 中而不是在其他一些data 属性...

You should be sure the response from Restangular getList() is in data.result and not in some other data property...

这篇关于Restangular getList() 返回空数组的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆