【发布时间】:2013-12-17 18:01:38
【问题描述】:
在 Angular 方面,我完全是个菜鸟,刚刚完成了一个 codeschool 教程,我已经遇到了我的第一个障碍。
我收到Error: [$resource:badcfg] Error in resource configuration. Expected response to contain an array but got an object
这是我的代码:
var bulletinApp = angular.module('bulletinApp', ['ngResource']);
bulletinApp.controller('PostsController', ['$scope', 'Post', function($scope, Post) {
$scope.heading = 'Welcome';
$scope.posts = Post.query();
$scope.newPost = {
title: 'Test Post'
}
}]);
bulletinApp.factory('Post', ['$resource', function($resource) {
return $resource('/posts');
}]);
我在这里找到了答案: Error in resource configuration while using $resource.query() function with AngularJS/Rails
也就是说我应该将其添加到我的资源声明中:
'query': {method: 'GET', isArray: false }
问题是我不知道我应该在哪里添加这个,或者即使这是我遇到的问题?
编辑:
bulletinApp.factory('Post', ['$resource', function($resource) {
return $resource('/posts', {'query': {method: 'GET', isArray: false}});
}]);
在此之后我仍然收到错误消息。同样在本教程中,没有必要这样做,我已经非常关注它,为什么 get 方法会获取对象而不是数组?
【问题讨论】:
-
谢谢,刚刚看了,估计你可以检查我的编辑,看看我是否添加正确?
标签: angularjs