I am trying to connect AngularJS with MongoDB using Mongoose. I would like to pass the Models to be used by the Controllers, so I can $scope to the data. I am not sure if I have to go about setting up an Angular Service, if so, can you point me in the right direction. Thank You.
Overview:
Model:
var mongoose = require('mongoose');
var db = mongoose.createConnection('mongodb://localhost:3000/database');
var orderSchema = new mongoose.Schema({
routeFrom : String,
routeTo : String,
leaving: String
});
var Order = db.model('Order', orderSchema);
module.exports = Order;
Controller:
// of course 'require' does not work but you get the idea
function OrderController($scope) {
return $scope.orders = Order.find({});
}
See Question&Answers more detail:
os 与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…