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