0

when i use the following code in my angularJs controller

var  baseAccount = Restangular.all('account');
    $scope.submit = function(){      
        baseAccount.getList().then(function(accounts) {
            $scope.datas = accounts ;
        });

i get the following error, Response for getList SHOULD be an array and not an object or something else in restangular

is there any solution ?

Ravindra Miyani
  • 360
  • 6
  • 14

1 Answers1

3

You're calling getList. which expects the data from the server to be an array (once it's been parsed into a real JS object). Your response is not an array.

You need to fix the server side code to respond with an array or change the Angular code to request a single resource instead of an array of them:

var baseAccount = Restangular.all('account');
$scope.submit = function () {
    baseAccount.get().then(function (account) {
        $scope.data = account; // Only one account
    });
};
James Allardice
  • 164,175
  • 21
  • 332
  • 312
  • yes, i had change the code at server side and works as expected :). Thanks for the help – Ravindra Miyani Mar 27 '14 at 08:15
  • You may also inform Restangular which object property contains the array you're intending to retrieve a list from: https://github.com/mgonto/restangular#my-response-is-actually-wrapped-with-some-metadata-how-do-i-get-the-data-in-that-case There's another SO example here too : http://stackoverflow.com/questions/22012655/restangular-getlist-with-object-containing-embedded-array – pc-pdx Mar 28 '14 at 03:42