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

北城余情 提交于 2020-01-06 13:59:59

问题


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 ?


回答1:


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


来源:https://stackoverflow.com/questions/22681370/response-for-getlist-should-be-an-array-and-not-an-object-or-something-else-in-r

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