错误:[$resource:badcfg] 资源配置错误.包含数组但得到对象的预期响应? [英] Error: [$resource:badcfg] Error in resource configuration. Expected response to contain an array but got an object?
问题描述
如何修复错误:
[$resource:badcfg] 资源配置错误.预期回应包含一个数组但得到一个对象?
[$resource:badcfg] Error in resource configuration. Expected response to contain an array but got an object?
//服务
angular.module('admin.services', ['ngResource'])
// GET TASK LIST ACTIVITY
.factory('getTaskService', function($resource) {
return $resource('../rest/api.php?method=getTask&q=*',{ 'get': {method:'GET'}});
})
//控制器
$scope.getTask = getTaskService.query(function (response) {
angular.forEach(response, function (item) {
if (item.numFound > 0) {
for(var i = 0; i < item.numFound; i++) {
$scope.getTasks[i] = item.docs[i];
}
}
});
});
推荐答案
首先你应该以不同的方式配置 $resource
:在 URL 中没有查询参数.默认查询参数可以作为 resource(url, paramDefaults, actions)
中第二个参数的属性传递.还要提到的是,您配置了资源的 get
方法并使用 query
代替.
First of all you should configure $resource
in different manner: without query params in the URL. Default query parameters may be passed as properties of the second parameter in resource(url, paramDefaults, actions)
. It is also to be mentioned that you configure get
method of resource and using query
instead.
服务
angular.module('admin.services', ['ngResource'])
// GET TASK LIST ACTIVITY
.factory('getTaskService', function($resource) {
return $resource(
'../rest/api.php',
{ method: 'getTask', q: '*' }, // Query parameters
{'query': { method: 'GET' }}
);
})
文档
http://docs.angularjs.org/api/ngResource.$resource
这篇关于错误:[$resource:badcfg] 资源配置错误.包含数组但得到对象的预期响应?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!