如何使用AngularJS在相应的按钮单击中从数据库中删除id中的特定行

时间:2016-05-08 07:39:19

标签: angularjs angularjs-directive html-table

我想通过使用angularJS从数据库中删除一行Html表及其ID,我是angularJS的新手,所以有什么方法可以实现这个目标吗?在此先感谢

我使用过这样的表

<table class="table details">
<thead> 
<tr>
<th sort-by="firstName">Title Initial_Phase</th>
<th sort-by="lastName">Travel From</th>
<th sort-by="created_at">Travel To</th>
<th sort-by="birthDate" sort-init="desc">From-To Date</th>
<th sort-by="birthDate" sort-init="desc">Budget</th>
<th sort-by="birthDate" sort-init="desc">Action</th>
</tr>
</thead>

<tbody>
<tr ng-repeat="issue in issues | filter:filter">
<td><strong><a href="/ViewBid/Index?{{ issue.ID }}" />{{ issue.Title }}             </strong></td>

<td><a href="/ViewBid/Index?{{ issue.ID }}" />{{ issue.Travel_From }}</td>
<td><a href="/ViewBid/Index?{{ issue.ID }}" />{{ issue.Travel_To }}</td>
<td><a href="/ViewBid/Index?{{ issue.ID }}" />{{ issue.From_Date | date }} -        {{ issue.To_Date | date }}</td>

<td><a href="/ViewBid/Index?{{ issue.ID }}" />{{ issue.Budget_Max }}</td>
<td><button type="button">Delete</button></td>
</tr>
</tbody>
</table>

1 个答案:

答案 0 :(得分:0)

这是一个例子:

<table class="table table-bordered"
    <thead><th>Name </th>
            <th>Delete</th>
    </thead>
 <tbody>
     <tr ng-repeat="data in List">
            <td>{{data.Name }}</td>
            <td> <input type="button" value="Delete" class="btn btn-danger btn-sm"
     ng-bootbox-confirm='R U Sure to Delete' ng-bootbox-confirm-action="delete(data)" ng-bootbox-confirm-action-cancel="confirmCallbackCancel   

(attr1, attr2)" /></td>
    </tr>

`

这是角度控制器:

`$scope.delete = function (data) {
        AngularService.delete(data)
        .success(function (data) {
            alert("Data Delete");
        })
        .error(function () {
            $ngBootbox.alert('@Resources.ResourceCommon.MsgNot_deleted');
        });
    }`   

在Angular Factory

 delete: function (data) {
            return $http({
                url: 'url path',
                method: 'POST',
                data: data
            })
        }