我在这里使用 angular.js 和 alertify.js 列出用户:
问题是:单击删除菜单后,会出现一个确认窗口,然后单击确定按钮后,删除的行仍然存在,直到您再次单击删除按钮。
看来,Angular 不知道何时更新自己。任何人都知道如何在 Angular 中正确地“重新加载”这个用户表?
这是我的html文件:
<table class="table">
<tbody>
<tr ng-repeat="user in users">
<td>{{ user.name }}</td>
<td>{{ user.age }}</td>
<td>
<button class="btn btn-danger" ng-click="removeUser($index)">
Delete
</button>
</td>
</tr>
</tbody>
</table>
这是我的函数 app.js :
var app = angular.module('demo', []);
app.controller('DemoCtrl', function($scope, $http) {
$scope.users = [
{name: "Jack", age: 10},
{name: "Bart",age: 20},
{name: "Griffin",age: 40}]
$scope.removeUser = function(index) {
alertify.confirm("You Sure ?").set('onok', function() {
$scope.users.splice(index, 1)
})
}
});