javascript 资源配置错误。包含一个对象但得到一个数组的预期响应
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/24409220/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me):
StackOverFlow
Error in resource configuration. Expected response to contain an object but got an array
提问by helloworld
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).
我有一个角度响应,需要一个数组,服务调用传递一个数组(可以在 Chrome 开发工具的网络选项卡中看到它)。
but I'm getting the following error in chrome console.
但我在 chrome 控制台中收到以下错误。
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?
我的 angularjs 版本是 1.2.15 有人能指出我的根本原因吗?
回答by Ronald91
Change tileServiceCall.get(..)
to tileServiceCall.query(...)
.
更改tileServiceCall.get(..)
为tileServiceCall.query(...)
。