不好意思第一次發文,所以再重新發一次!
我想問的問題是,我想刪掉列表出來的項目,
畫面可以刪除,但是後端接收不到。
HTML部分:
<body>
<div ng-controller="firstCtrl">
書名:<input type="text" ng-model="name" placeholder="輸入書名">
作者:<input type="text" ng-model="author" placeholder="輸入作者">
<button type="button" ng-click="add()">新增</button>
<button type="button" ng-click="showList()">列出</button>
<table class="table table-striped" >
<tr colspan="5">
<td></td>
<td>ID</td>
<td>書名</td>
<td>作者</td>
<td></td>
</tr>
<tr ng-repeat="data in list">
<td><a href="" ng-click="remove($index)">X</a></td>
<td>{{data.id}}</td>
<td><span ng-hide="isShow"></span>
<span>
<input ng-show="isShow" type="text" ng-model="nameEdit" >
</span>
</td>
<td>{{data.author}}</td>
<td>
<button type="button" ng-click="editShow(data)">
<span ng-hide="isShow">修改</span>
<span ng-show="isShow">確認</span>
</button>
<button type="button">取消</button>
</td>
</tr>
</table>
<button ng-hide="clear" type="button" ng-click="rset()">全部清除</button>
</div>
JS部分:
$scope.list = []
$scope.clear = true;
$scope.showList = function() {
$http({
url: 'http://localhost:2000/book',
method: 'GET',
}).then(function(success_response) {
console.log(success_response);
$scope.list = success_response.data;
}, function(err_response) {
console.log(err_response);
})
if ($scope.clear = true) {
$scope.clear = false;
}
}
//刪除
$scope.remove = function(idx) {
$scope.list.splice(idx, 1)
var id = $scope.list.id;
$http.delete('http://localhost:2000/book/', { id: id }).then(function(res) {
$scope.showList(res);
console.log(idx);
})
}