我正在使用ng-model,我想在ng-model中添加$ index,但它无法正常工作。任何人都可以帮助我放置$ index。
感谢
我已更新完整代码: -
这是我的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="Bookentry.item.Reference[$index]" ng-maxlength="8" ng-minlength="1"></input>
<input type="text" name="Remarks" ng-model="Bookentry.item.Remarks[$index]" ng-maxlength="8" ng-minlength="1"></input>
<button type="submit">Save</button>
</ng-form>
</div>
</form>
我的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);
});
};
我的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)
});
});
});