2

I know this question has been asked many times. I have this error :

Response for getList SHOULD be an array and not an object or something else

The problem is that my response IS an array

[{"id":1,"token":"HOME","traductions":[{"id":1,"value":"accueil","langue":{"id":1,"langue":"fran\u00e7ais","locales":"fr_FR"}},{"id":2,"value":"home","langue":{"id":2,"langue":"anglais","locales":"en_EN"}}]},{"id":2,"token":"CONTACT","traductions":[{"id":3,"value":"contact","langue":{"id":1,"langue":"fran\u00e7ais","locales":"fr_FR"}}]}]

Here is my simple controller

traduction.controller('traductionController', ['$scope', 'Restangular', function($scope, Restangular) {

    var containers = Restangular.all('intranetBS/web/app_dev.php/interne/traductions'); // correct route, checked it

    containers.getList().then(function(stuff) {
         $scope.containers = stuff;
    });

}]);

Any solution ? Thank you very much !!

ovesco
  • 633
  • 1
  • 8
  • 22
  • Are you sure this is the response received when you're actually executing that restangular code and not, say, testing endpoint manually in the console? Last time I got this error, it was because restangular was getting error html page instead of json (or something like that. certainly not getting the expected json) – Sergio Tulentsev Apr 02 '15 at 11:08
  • possible duplicate of [Response for getList SHOULD be an array and not an object or something else in restangular](http://stackoverflow.com/questions/22681370/response-for-getlist-should-be-an-array-and-not-an-object-or-something-else-in-r) – dting Apr 02 '15 at 11:10
  • @DTing: not sure if these two really are duplicates. This response *is* an array. – Sergio Tulentsev Apr 02 '15 at 11:15

1 Answers1

2
.config(function(RestangularProvider){
   RestangularProvider.setBaseUrl('/api');
   RestangularProvider.addResponseInterceptor(function(data, operation, what, url, response, deferred) {
      var extractedData;
      if (operation === "getList") {
        extractedData = data.traductions;
      } else {
        extractedData = data;
      }
      return extractedData;
    });
})
wcc526
  • 3,915
  • 2
  • 31
  • 29