Search code examples
angularjsangularjs-ng-repeatng-hide

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?


Solution

  • 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;
         });
    });