Restangular getList()返回空数组

时间:2016-09-08 13:44:30

标签: angularjs rest restangular

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

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文件中定义了以下配置

 .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;
  });
})

控制台

Console

网络

Network

1 个答案:

答案 0 :(得分:0)

您应该确定Restangular getList()的回复位于data.result,而不是其他data属性...