[英]ng-repeat with filter not updating
I'm building an ionic app. 我正在构建一个离子应用程序。 I have a state where the user can see all of their posts.
我处于一种状态,用户可以看到他们的所有帖子。 Each post has many fields, one of which is 'active' - boolean field.
每个帖子都有许多字段,其中一个是“活动”字段-布尔字段。
I'm rendering the list by: 我通过以下方式呈现列表:
<ion-item ng-repeat="post in posts | filter:{active:true}" ng-click="goToPost(post.id)"
class="item item-thumbnail-left">
<some fields here />
</ion-item>
Then the user has an option to deactivate a post. 然后,用户可以选择停用帖子。
<ion-option-button class="button-assertive" ng-click="deactivate(post.id, $index)">
DEACTIVATE
</ion-option-button>
This option makes a request to the backend, and also it locally sets the active field of the post into "false". 此选项向后端发出请求,并且在本地将帖子的活动字段设置为“ false”。 After the deactivation is complete, I can't get the ng-repeat to re-filter the list - since the current post should no longer appear in the list of active posts.
停用完成后,我无法获得ng-repeat来重新过滤列表-因为当前帖子不应再出现在活动帖子列表中。
I tried $scope.$apply() and it threw the $digest error... I tried to add ng-change and ng-model, and that didn't work either. 我尝试了$ scope。$ apply(),并抛出了$ digest错误...我试图添加ng-change和ng-model,但这也不起作用。 I also tried reloading the state completely, but for some reason, I can't get this done.
我也尝试完全重新加载状态,但是由于某种原因,我无法完成此任务。 Can anyone help me?
谁能帮我? Thanks in advance!
提前致谢!
<div ng-app="app" ng-controller="demoController">
<ion-item ng-repeat="post in data | filter:{activated:true}" ng-click="deativate(post.id)">
{{post.col1}} {{post.activated }} {{"click Me"}} </br>
</ion-item>
</div>
var app= angular.module("app",[]);
app.controller('demoController', ['$scope',
function($scope) {
$scope.data = [
{id:1,col1:"abc",activated:true},
{id:2,col1:"abc1",activated:true},
{id:3,col1:"abc2",activated:true},
{id:4,col1:"abc3",activated:true},
{id:5,col1:"abc4",activated:false},
{id:6,col1:"abc5",activated:true},
];
$scope.deativate = function(id){
angular.forEach($scope.data,function(item){
if(item.id === id){
item.activated = false;
}
})
}
}]);
and for your code you can share your code snippet. 对于您的代码,您可以共享您的代码段。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.