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

1

18

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?

Stereotype answered 25/6, 2014 at 12:53 Comment(0)
S
50

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

Sober answered 25/6, 2014 at 12:59 Comment(1)
I stuck in this problem for an hour until i found your post. It work!!! Thank you.Centurial

© 2022 - 2024 — McMap. All rights reserved.