[英]How to submit after using ng-repeat, ng-form and ng-submit
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 1100-500-指环王参考(InputBox)备注(InputBox)SubmitBox
2 1002 - 570 - Harry Potter Reference(InputBox) Remarks(InputBox) SubmitBox 21002-570-哈利波特参考(InputBox)备注(InputBox)SubmitBox
3 1003 - 720 - Davinci Code Reference(InputBox) Remarks(InputBox) SubmitBox 3 1003-720-达芬奇代码参考(InputBox)备注(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:- 这是我的html代码:-
<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:- 我的core.js代码是:-
$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.js是:
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:
html代码:
<form name="Bookentry" ng-submit="save(lists)">
core js: 核心js:
$scope.save = function(bookEntry){
$http.post('/api/save',bookEntry)
.success(function(data){
$scope.list = {};
$scope.list.Books = data;
})
.error(function(data){
console.log('Error: ' + data);
});
};
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.