I am using some data to get a list of Books as below:-
1 1001 - 500 - Lords of the Ring Reference(InputBox) Remarks(InputBox) SubmitBox
2 1002 - 570 - Harry Potter Reference(InputBox) Remarks(InputBox) SubmitBox
3 1003 - 720 - Davinci Code Reference(InputBox) Remarks(InputBox) SubmitBox
I am able to get above with codes below. But however, I do not know how to save the datas to another database and would be grateful if someone could guide me.
This is my html code:-
<form name="Bookentry" ng-submit="save()">
<div ng-repeat="lists in list.Books | orderBy: ['numB','numB1' ]">
<ng-form name="item">
{{$index+1}}
<input type="checkbox" ng-click="delete(lists._id)">{{lists.numB}} - {{lists.numB1}} - {{lists.bookname}}
<input type="text" name="Reference" ng-model="lists.Reference" ng-maxlength="8" ng-minlength="1"></input>
<input type="text" name="Remarks" ng-model="lists.Remarks" ng-maxlength="8" ng-minlength="1"></input>
<button type="submit">Save</button>
</ng-form>
</div>
</form>
My core.js codes is:-
$scope.save = function(){
$http.post('/api/save',$scope.Bookentry)
.success(function(data){
$scope.list = {};
$scope.list.Books = data;
})
.error(function(data){
console.log('Error: ' + data);
});
};
My app.js is:
app.post('/api/save', function(req,res){
dbBooks.create({
numB: req.body.numB,
numB1: req.body.numB1,
name: req.body.bookname,
Reference: req.body.Reference,
remarks: req.body.remarks,
done: false
}, function(err,result){
if (err)
res.send(err);
dbBooks.find(function(err,result){
if (err)
res.send(err)
res.json(result)
});
});
});
You can pass the lists model as parameter to the save function. html code:
core js: