如何显示已隐藏的ng-repeat项目

时间:2021-07-10 07:20:29

I have an ng-repeat that looks like this:

我有一个ng-repeat,看起来像这样:

<div class="name" ng-hide="name.hide" ng-repeat="name in nameArray" ng-click="checkName(name)">

When one of the ng-repeat elements is clicked, I need it to be hidden so, in my controller, I'm doing this:

当点击其中一个ng-repeat元素时,我需要隐藏它,所以,在我的控制器中,我这样做:

$scope.checkName = function(name){
   name.hide = true;
}

That all works fine but I need to figure out a way to show all hidden ng-repeat items again after the user leaves this view and then returns to it from another view.

一切正常,但我需要找出一种方法,在用户离开此视图后再次显示所有隐藏的ng-repeat项目,然后从另一个视图返回到该视图。

Any ideas?

2 个解决方案

#1


1  

If your data is indeed in a service (which is why it is kept alive, since services are singletons and do not get destroyed as you navigate between routes), then you can do a sort of a reset to the hide property when you navigate away from your view.

如果你的数据确实存在于服务中(这就是为什么它保持活着,因为服务是单例并且在你在路由之间导航时不会被破坏),那么当你离开时你可以对hide属性进行一种重置从你的角度来看。

Place this in your controller code:

将其放在您的控制器代码中:

$scope.$on('$destroy', function () {
     angular.forEach(nameArray, function (item) {
          item.hide = false;
     });
});

#2


0  

You can try to store all the hidden name in a service and have a lookup in the controller each time a view use the controller.

您可以尝试将所有隐藏名称存储在服务中,并在每次视图使用控制器时在控制器中进行查找。

#1


1  

If your data is indeed in a service (which is why it is kept alive, since services are singletons and do not get destroyed as you navigate between routes), then you can do a sort of a reset to the hide property when you navigate away from your view.

如果你的数据确实存在于服务中(这就是为什么它保持活着,因为服务是单例并且在你在路由之间导航时不会被破坏),那么当你离开时你可以对hide属性进行一种重置从你的角度来看。

Place this in your controller code:

将其放在您的控制器代码中:

$scope.$on('$destroy', function () {
     angular.forEach(nameArray, function (item) {
          item.hide = false;
     });
});

#2


0  

You can try to store all the hidden name in a service and have a lookup in the controller each time a view use the controller.

您可以尝试将所有隐藏名称存储在服务中,并在每次视图使用控制器时在控制器中进行查找。