Re: [問題] anglural 新手問題...
不好意思第一次發文,所以再重新發一次!
我想問的問題是,我想刪掉列表出來的項目,
畫面可以刪除,但是後端接收不到。
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);
})
}
--
※ 發信站: 批踢踢實業坊(ptt.cc), 來自: 36.226.218.32
※ 文章網址: https://www.ptt.cc/bbs/Ajax/M.1464460451.A.9FF.html
推
05/29 02:40, , 1F
05/29 02:40, 1F
→
05/29 02:42, , 2F
05/29 02:42, 2F
推
05/29 09:30, , 3F
05/29 09:30, 3F
→
05/29 09:30, , 4F
05/29 09:30, 4F
→
05/29 09:30, , 5F
05/29 09:30, 5F
→
05/29 09:30, , 6F
05/29 09:30, 6F
→
05/29 15:49, , 7F
05/29 15:49, 7F
→
05/29 15:50, , 8F
05/29 15:50, 8F
推
05/30 01:25, , 9F
05/30 01:25, 9F
→
05/30 01:25, , 10F
05/30 01:25, 10F
推
06/07 17:54, , 11F
06/07 17:54, 11F
→
06/07 17:56, , 12F
06/07 17:56, 12F
→
06/07 17:57, , 13F
06/07 17:57, 13F
討論串 (同標題文章)
完整討論串 (本文為第 2 之 2 篇):
Ajax 近期熱門文章
PTT數位生活區 即時熱門文章