嘿伙计们我想在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>
控制器:
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)
。
答案 0 :(得分:3)
替换
<a href="#" id="tagaDelete" data-ng-click="deleteItem({{student.id}})">Delete</a>
通过
<a href="#" id="tagaDelete" data-ng-click="deleteItem(student.id)">Delete</a>