Banjo Drill
Banjo Drill

Reputation: 121

How do I show an ng-repeat item that has already been hidden

I have an ng-repeat that looks like this:

<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:

$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.

Any ideas?

Upvotes: 0

Views: 220

Answers (2)

Omri Aharon
Omri Aharon

Reputation: 17064

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.

Place this in your controller code:

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

Upvotes: 1

Johnny Ha
Johnny Ha

Reputation: 633

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.

Upvotes: 0

Related Questions