Speso ore cercando di capirlo - sto aggiungendo un nuovo modello alla mia app, ma non funziona con "TypeError: List.find non è una funzione". Ho un altro modello, Articoli, che è impostato nello stesso modo e sta funzionando bene. Le cose sembrano fallire nel percorso, ma funziona se lo collego al modello Item. Sto dichiarando lo schema in modo errato? Devo iniziare il modello in Mongo o qualcosa del genere?Mongoose Model.find non è una funzione?
modello
var mongoose = require('mongoose');
var Schema = mongoose.Schema;
var listSchema = new Schema({
name: { type: String, default: datestring + " List" }
});
mongoose.exports = mongoose.model('List', listSchema);
percorso
app.get('/lists', function (req, res, err) {
List.find(function (err, docs){ //THIS IS WHAT'S FAILING
res.json(docs);
});
});
regolatore
angular.module('pickUp').controller('ListsCtrl', ['$scope', '$http', 'ngDialog', 'lists',
function($scope, $http, ngDialog, lists) {
$scope.lists = lists.lists;
}]);
fabbrica
angular.module('pickUp').factory('lists', ['$http',
function($http){
var lists = {
lists: []
};
lists.getAll = function(){
console.log("trying. . .");
$http.get('/lists').success(function(res){
angular.copy(res, lists.lists);
});
};
return lists;
}]);
config
$stateProvider
.state('/', {
url: '/',
templateUrl: 'views/lists.html',
controller: 'ListsCtrl',
resolve: {
listPromise: ['lists', function (lists){
return lists.getAll();
}]