从我的收藏中删除一个条目后,删除的对象的值消失了,但行(空白)仍然存在。(尝试了apply()...没有成功)
我有一个典型的CRUD ui,其中包含费用。
<table class="table table-striped">
<tr>
<td>Titre</td>
<td>Date</td>
<td>Montant</td>
<td>Méthode de paiement</td>
<td></td>
<td></td>
</tr>
<tr ng-repeat="expense in expenses">
<td>{{expense.title}}</td>
<td>{{expense.date}}</td>
<td>{{expense.amount}}</td>
<td>{{expense.paiementMethod}}</td>
<td><a class="btn btn-primary" ui-sref="editExpense({id:expense._id})">Editer</a></td>
<td><a class="btn btn-primary" ng-click="deleteExpense(expense)">Supprimer</a> </td>
</tr>
</table>
绑定到费用控制器
angular.module('ExpenseCtrl', [])
.controller('ExpenseListController', function ($scope, $state, $window,Expense) {
$scope.expenses = Expense.query();
$scope.deleteExpense = function (expense) {
expense.$delete(function () {
$state.go('expenses');
})
}
})
由费用资源工厂提供
angular.module('ExpenseService', []).factory('Expense', function($resource) {
return $resource('api/expenses/:id',{
id:'@_id'},{
update:{method:'PUT'}, delete:{method:'DELETE'}})
});
与Json API通信(mongodb和后面的node / express)
因此,我使用ngResource&amp; ui.router处理状态场景。
注意:如果我从删除功能手动刷新,一切都还可以,但是我们有要做什么?
.controller('ExpenseListController', function ($scope, $state, $window,Expense) {
$scope.expenses = Expense.query();
$scope.deleteExpense = function (expense) {
expense.$delete(function () {
$scope.expenses = Expense.query();
})
}
})
答案 0 :(得分:2)
您必须以某种方式将其从作用域上的expenses
数组中删除,无论是通过重新查询还是仅在成功删除服务器端时将其从阵列中删除。 $http
请求本身不会影响$scope.expenses
对象。