Den*_*Hiu 2 javascript angularjs angularjs-ng-repeat alertifyjs
我正在使用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>
Run Code Online (Sandbox Code Playgroud)
这是我的函数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)
})
}
});
Run Code Online (Sandbox Code Playgroud)
您可以使用$ scope.$ apply()通知Angular您在alertify上下文中所做的更改:
$scope.$apply(function() {
$scope.users.splice(index, 1)
});
Run Code Online (Sandbox Code Playgroud)
| 归档时间: |
|
| 查看次数: |
1468 次 |
| 最近记录: |