Restangular getList() returning empty array

2019-07-29 06:20发布

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

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

Console

Console

Network

Network

1条回答
地球回转人心会变
2楼-- · 2019-07-29 07:12

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

查看更多
登录 后发表回答