Error in resource configuration. Expected response to contain an object but got an array

时光毁灭记忆、已成空白 提交于 2019-11-30 16:31:12

问题


I have an angular response that expects an array and the service call passes an array(can see it in network tab of chrome dev tools).

but I'm getting the following error in chrome console.

Error in resource configuration. Expected response to contain an object but got an array

here is my angular service:-

physicalServerModule.factory("physicalServerServices", ['$resource',
function ($resource) {

    var host = app.general.host;
    var port = app.general.port;

    var serverItemPath = 'v1/physicalserver/:x';
    var serverPath = 'v1/physicalserver/list';


    return {
        physicalServer: function () {
            return $resource(host + serverPath,{}, {
                query: {
                    method: 'GET',
                    isArray: true
                },
                create: {
                    method: 'POST'
                }
            });
        }
};
}]);

and I'm calling my service as below:-

var tileServiceCall = physicalServerServices.physicalServer();
tileServiceCall.get({},{}).$promise.then(function (response) {


 app.meta.physicalserver.tileItems = JSON.stringify(response);

}, function (error) {
alert("error");

});

my angularjs version is 1.2.15 can someone point me the root cause?


回答1:


Change tileServiceCall.get(..) to tileServiceCall.query(...).



来源:https://stackoverflow.com/questions/24409220/error-in-resource-configuration-expected-response-to-contain-an-object-but-got

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