# How to save ng-show boolean value into the $localStorage or ngStorage?

**URL:** <https://forum.ionicframework.com/t/how-to-save-ng-show-boolean-value-into-the-localstorage-or-ngstorage/36539>\
**Category:** ionic-v1\
**Created:** [November 7, 2015, 10:26am UTC](https://forum.ionicframework.com/t/how-to-save-ng-show-boolean-value-into-the-localstorage-or-ngstorage/36539 "2015-11-07T10:26:49Z")\
**Posts on this page:** 5\
**Page:** 1

<div class="post-metadata">

**Author:** ![emsee71](https://sea1.discourse-cdn.com/ionicframework/user_avatar/forum.ionicframework.com/emsee71/32/13626_2.png) [@emsee71](https://forum.ionicframework.com/u/emsee71)\
**Post date:** [November 7, 2015, 10:26am UTC](https://forum.ionicframework.com/t/how-to-save-ng-show-boolean-value-into-the-localstorage-or-ngstorage/36539/1 "2015-11-07T10:26:49Z")

</div>

Hi can you help me, is there any solution how to save ng-show boolean vaue into the $ocalStorage or ngStorage?

I have an example of my code here but it’s not working, Please help me:

```
example.controller("ExampleController", function($scope,$localStorage) {
 
  $localStorage.showDiv;

  $scope.showPermanently = function(){
    $scope.showMe = true; // set the ng-show value into true
    $localStorage.showDiv = $scope.showMe; / /transfer the showMe value into ngStorage

  }

   $scope.hidePermanently = function(){
    $scope.showMe = false; // set the ng-show value into true
    $localStorage.showDiv = $scope.showMe;/ /transfer the showMe value into ngStorage

  }
   
    
   
 
});

 <ion-content ng-controller="ExampleController">
  
  <br><br><br>

  <button class="button" ng-click="hidePermanently()">Hide Permanently</button>

  <button class="button" ng-click="showPermanently()">Show Permanently</button>

    <div ng-show="showMe">
      Hi I'm Saved Permanently !
    </div>

  </ion-content>
```

---

<div class="post-metadata">

**Author:** ![Sujan12](https://sea1.discourse-cdn.com/ionicframework/user_avatar/forum.ionicframework.com/sujan12/32/108395_2.png) [@Sujan12](https://forum.ionicframework.com/u/Sujan12)\
**Post date:** [November 7, 2015, 11:43am UTC](https://forum.ionicframework.com/t/how-to-save-ng-show-boolean-value-into-the-localstorage-or-ngstorage/36539/2 "2015-11-07T11:43:09Z")

</div>

You probably only need to `$scope.showMe = $localStorage.showDiv;` in the beginning of your controller so it gets the initial value from localStorage.

---

<div class="post-metadata">

**Author:** ![emsee71](https://sea1.discourse-cdn.com/ionicframework/user_avatar/forum.ionicframework.com/emsee71/32/13626_2.png) [@emsee71](https://forum.ionicframework.com/u/emsee71)\
**Post date:** [November 7, 2015, 5:48pm UTC](https://forum.ionicframework.com/t/how-to-save-ng-show-boolean-value-into-the-localstorage-or-ngstorage/36539/3 "2015-11-07T17:48:45Z")

</div>

Wow ! Great Thanks You saved my life 😃

---

<div class="post-metadata">

**Author:** ![emsee71](https://sea1.discourse-cdn.com/ionicframework/user_avatar/forum.ionicframework.com/emsee71/32/13626_2.png) [@emsee71](https://forum.ionicframework.com/u/emsee71)\
**Post date:** [November 7, 2015, 5:56pm UTC](https://forum.ionicframework.com/t/how-to-save-ng-show-boolean-value-into-the-localstorage-or-ngstorage/36539/4 "2015-11-07T17:56:00Z")

</div>

How about rootScope , are they also the same as scope in saving the boolean value into the $localStorage?

---

<div class="post-metadata">

**Author:** ![Sujan12](https://sea1.discourse-cdn.com/ionicframework/user_avatar/forum.ionicframework.com/sujan12/32/108395_2.png) [@Sujan12](https://forum.ionicframework.com/u/Sujan12)\
**Post date:** [November 7, 2015, 6:04pm UTC](https://forum.ionicframework.com/t/how-to-save-ng-show-boolean-value-into-the-localstorage-or-ngstorage/36539/5 "2015-11-07T18:04:05Z")

</div>

rootScope is the scope above all scopes. You can read more about it here: [https://docs.angularjs.org/api/ng/service/$rootScope](https://docs.angularjs.org/api/ng/service/%24rootScope)

But beware, scope is not localStorage. scopes are just the data container for the controllers and templates. Everything localstorage has to happen in a controller, that saves data to localStorage. scope ist then only used to be able to display it in a template.
