Restangular getList() returning empty array

梦想的初衷 提交于 2019-12-11 04:38:47

问题


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

Network


回答1:


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



来源:https://stackoverflow.com/questions/39392613/restangular-getlist-returning-empty-array

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!