花了好几个小时试图解决这个问题 - 我正在为我的应用添加一个新模型,但是它失败了"TypeError:List.find不是一个函数".我有另一个模型,项目,以相同的方式设置,并正常工作.事情似乎在路线上失败但是如果我把它连接到Item模型就可以了.我是否错误地声明了架构?我是否需要在mongo或其他东西中启动模型?
模型
var mongoose = require('mongoose');
var Schema = mongoose.Schema;
var listSchema = new Schema({
name: { type: String, default: datestring + " List" }
});
mongoose.exports = mongoose.model('List', listSchema);
Run Code Online (Sandbox Code Playgroud)
路线
app.get('/lists', function (req, res, err) {
List.find(function (err, docs){ //THIS IS WHAT'S FAILING
res.json(docs);
});
});
Run Code Online (Sandbox Code Playgroud)
调节器
angular.module('pickUp').controller('ListsCtrl', ['$scope', '$http', 'ngDialog', 'lists',
function($scope, $http, ngDialog, lists) {
$scope.lists = lists.lists;
}]);
Run Code Online (Sandbox Code Playgroud)
厂
angular.module('pickUp').factory('lists', ['$http',
function($http){
var lists = {
lists: []
};
lists.getAll = function(){
console.log("trying. . …Run Code Online (Sandbox Code Playgroud)