所以我是Angular的新手,我已经查看了其他各种解决方案,但似乎没有人能为我工作.我的应用程序需要从mongodb数据库中获取一些数据并将其显示给客户端.事情是我得到的
错误:[$ resource:badcfg]操作的资源配置出错
query.预期的响应包含一个数组但得到一个对象
这是我在客户端上的SchoolCtrl.js
app.controller('SchoolsCtrl', function($scope, SchoolResource) {
$scope.schools = SchoolResource.query();
});
Run Code Online (Sandbox Code Playgroud)
这是我的ngResource
app.factory('SchoolResource', function($resource) {
var SchoolResource = $resource('/api/schools/:id', {id: '@id'}, { update: {method: 'PUT', isArray: false}});
return SchoolResource;
});
Run Code Online (Sandbox Code Playgroud)
这是我在服务器上的SchoolsController
var School = require('mongoose').model('School');
module.exports.getAllSchools = function(req, res, next) {
School.find({}).exec(function(err, collection) {
if(err) {
console.log('Schools could not be loaded: ' + err);
}
res.send(collection);
})
};
Run Code Online (Sandbox Code Playgroud)
我尝试添加IsArray:true,尝试在资源中的'SchoolResource'之后添加[],尝试更改路由,没有任何效果.我想查看实际返回的内容,查询抱怨的不是数组,所以我将其转换为字符串,这就是结果:
function Resource(value){shallowClearAndCopy(value || {},this); }
我不知道它为什么返回一个函数.谁能帮我?
javascript mongodb node.js angularjs single-page-application