嘿伙计们,我想在 AngularJS 函数中按 id 删除项目。如何从删除按钮获取 id?
<table data-ng-app="myApp" data-ng-controller="myController">
<tbody>
<tr>
<th>ID</th>
<th>Name</th>
<th>School</th>
<th>Gender</th>
<th>Email</th>
<th>Update</th>
<th>Delete</th>
</tr>
<tr data-ng-repeat="student in students">
<td>{{student.id}}</td>
<td>{{student.name}}</td>
<td>{{student.school}}</td>
<td>{{student.gender}}</td>
<td>{{student.email}}</td>
<td><a href="#" id="tagaUpdate" >Update</a></td>
<td><a href="#" id="tagaDelete" data-ng-click="deleteItem({{student.id}})">Delete</a></td>
</tr>
</tbody>
</table>
Controller :
var myApp = angular.module('myApp', []);
myApp.controller("myController", function ($scope) {
$scope.deleteItem = function (id) {
alert(id);//it doesn't show alert here
};
});
我认为问题出在data-ng-click="deleteItem({{student.id}})"
。但是当我检查时,它显示了值 data-ng-click="deleteItem(5)
。
最佳答案
替换
<a href="#" id="tagaDelete" data-ng-click="deleteItem({{student.id}})">Delete</a>
由
<a href="#" id="tagaDelete" data-ng-click="deleteItem(student.id)">Delete</a>
关于javascript - 如何通过AngularJS删除一项?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/29342845/