问题
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