1
Hello, Everybody!
I’m starting a study in Electron and in this application I’m using Angularjs, the detail is that I don’t mean much about, and I can’t think of a way to use the Node without the server running, in order I would like to use the modules of the Node in a service of Angular.
I’ll try to go into more detail with the sources:
I have my user.model.js:
var mongoose = require('mongoose'),
Schema = mongoose.Schema;
var UserSchema = new Schema({
name: String,
password: String
});
module.exports = mongoose.model('User', UserSchema);
In my userService.js:
(function () {
'use strict';
var express = require('express'),
mongoose = require('mongoose'),
User = require('./user.model.js')
angular.module('app')
.service('userService', ['$q', UserService]);
function UserService($q) {
return {
create: createUser
/*getUsers: getUsers,
getById: getUserById,
destroy: deleteUser,
update: updateUser*/
};
function createUser(user) {
var deferred = $q.defer();
User.create(user, function(err, res) {
if(err) { eferred.reject(err); }
deferred.resolve(res);
});
return deferred.promise;
}
}
})();
And in my view controller (usuarioController.js)
(function () {
'use strict';
angular.module('app')
.controller('UsuarioController', ['userService', '$q', UsuarioController]);
function UsuarioController(userService, $q, $mdDialog) {
var self = this;
self.User = {};
self.saveUser = saveUser;
function saveUser($event) {
userService.create(self.User).then(function (res) {
console.log('Salvou' + res);
});
}
}
})();
If anyone knows how I can do that, I’d be very grateful!
Thanks @josivan , I think it’s actually better if I give a better study of the framework (Electron), because I really imagined that it just built the desktop application.
– Lucas Henrique de Abreu
@Lucashenriquedeabreu, the idea is that you make a web application run on the desktop on the platforms where Electron is available. Electron is a chromiun with built-in Node.
– josivan