错误的资源配置。预计响应包含一个对象,但得到的数组 [英] Error in resource configuration. Expected response to contain an object but got an array

查看:239
本文介绍了错误的资源配置。预计响应包含一个对象,但得到的数组的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有期望一个阵列和服务调用传递一个阵列的角度响应(可以看到它在Chrome浏览器开发工具的网络选项卡)。

但我发现在铬控制台下面的错误。


错误的资源配置。预计响应包含一个对象,但得到的数组

这是我的角度服务: -

  physicalServerModule.factory(physicalServerServices,['$资源',
功能($资源){    VAR主机= app.general.host;
    VAR端口= app.general.port;    VAR serverItemPath ='V1 / physicalserver /:X';
    VAR SERVERPATH ='V1 / physicalserver /名单;
    返回{
        physicalServer:功能(){
            返回$资源(主机+ SERVERPATH,{},{
                查询:{
                    方法:GET,
                    IsArray的:真
                },
                创建: {
                    方法:POST
                }
            });
        }
};
}]);

和我下面喊我的服务: -

  VAR tileServiceCall = physicalServerServices.physicalServer();
tileServiceCall.get({},{})$。promise.then(功能(响应){
 app.meta.physicalserver.tileItems = JSON.stringify(响应);},功能(错误){
警报(错误);});

我angularjs的版本是1.2​​.15
可有人点我的根本原因?


解决方案

修改 tileServiceCall.get(..) tileServiceCall.query(。 ..)

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?

解决方案

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

这篇关于错误的资源配置。预计响应包含一个对象,但得到的数组的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
相关文章
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆