angularjs – 错误:[$resource:badcfg]资源配置中的错误 包含
发布时间:2020-12-17 09:06:31 所属栏目:安全 来源:网络整理
导读:如何解决错误: [$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
如何解决错误:
//服务 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中没有查询参数。默认查询参数可以作为资源(url,paramDefaults,actions)中第二个参数的属性传递。还要提到您配置资源的get方法并使用查询。
服务 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 (编辑:李大同) 【声明】本站内容均来自网络,其相关言论仅代表作者个人观点,不代表本站立场。若无意侵犯到您的权利,请及时与联系站长删除相关内容! |