Sharing object between backend and frontend in angular-fullstack env
What is the best way to use same object for mongose schema and angular controler?
var mongoose = require('mongoose'),
Schema = mongoose.Schema;
var sharedObject = {
name: String,
info: String,
active: Boolean
};
var MissionSchema = new Schema(sharedObject);
module.exports = mongoose.model('Mission', MissionSchema);
AND
angular.module('myApp')
.controller('MyCtrl', function ($scope, $http, socket, sharingService) {
var sharedObject = sharingService('myObjectSchema');
generateForm(sharedObject);
});
Any helpful info appreciated, thanks :)
The newest versions of Mongoose include a way to share schema validation between client & server, but I haven't really looked into it yet. You might start there.
Thank you @Awk34, you pushed me closer. I have found this mongoose docs page. But still I cant see how I can extract Schema from mongoose object. :/
The doc explains how to create Schema objects on the front-end. You'll need a way to include the duplicate data that's needed from the back-end & front-end. Maybe having a schemas folder that is used by both the server and client. It would be useful to include an example recipe of this in the generator/docs.
fantastick
+1, I have the same question