Having trouble with posting data back to mongodb - when I click submit, it's not sending anything. The command prompt shows {} and the network console hangs on pending before eventually failing due to a long delay in posting.
Could use some help figuring this out, thanks in advance.
HTML:
<input type="text" ng-model="vm.user">
<input type="text" ng-model="vm.pass">
Service:
function _postUser(user, pass){
var params = {
user: user,
pass: pass
}
return $http({
method: 'POST',
url: '/loginDB',
params: params
})
}
Fetching users from the database:
vm.getUsers = function (){
homeService.getUsers()
.then(function(response){
vm.users = response.data;
console.log(vm.users);
});
}
Posting action:
vm.postUser = function() {
// console.log('send it back')
homeService.postUser(vm.user)
.then(function(response){
console.log('send it back')
})
}
Server.js handling post request to the database:
app.post('/loginDB', function (req, res){
console.log(req.body);
});
Update: Data is now being posted but not capturing the ng-model values. I suspect an issue with the ng-model but can't pinpoint it.
db.loginDB.insert(req.body, function(err, doc){
res.json(doc);
})