Saved Events

Hi, There , Is there any solution to save all the events you did after you close your app?
Ex:

<ion-ontent ng-controller="controller">
<div ngShow = "showMe">
</div>
</ion-content>

.controller('controller',function($scope){
$scope.showMe = true;  // Saved this event to my app

})

if you only need to store flags or simple,short strings you can use the localStorage for that. If you want to store complex and huge datasets use PouchDB, SQLite or WebSQL (or oldschool but easy --> write a json file)

Can you please give me some examples , how can I use these short flags in my problem ?

the easiest way:

localStorage.setItem('showMe', 1); // sets new value for key showMe

localStorage.getItem('showMe'); // return "1" as a string!

localStorage.removeItem('showMe'); // removes a flag

this works in mostly all moden browsers.

If you do not want to check if there is localstorage and so on you can use:


or

as a wrapper

1 Like

Is it okay to store a $scope.showMe , inside the localstorage? like this ?

<ion-ontent ng-controller="controller">
<div ngShow = "showMe">
</div>
</ion-content>

.controller('controller',function($scope){
    localStorage.setItem('$scope.showMe=true', 1); // sets new value for key showMe
    
    localStorage.getItem('$scope.showMe=true'); // return "1" as a string!
    
    localStorage.removeItem('$scope.showMe=true'); // removes a flag
})

yeah but it should look like this:

localStorage.setItem('showMe', 1); // sets new value for key showMe
localStorage.getItem('showMe'); // return "1" as a string!    
localStorage.removeItem('showMe'); // removes a flag

first parameter is a key (you do not need to use “$scope.” as a prefix. and the second param is the value (keep in mind localstorage stores only string so instead of the number 1 it will store “1”.
Removing and getting is done with the previously used key.

Is ngStorage also can be applied in saving events ?

yeah but localstorage is not made to store huge data sets… so keep in mind the limitations of localstorage is about 5mb

and how about ngStorage ? How much memory limit does this take ?

does not matter. i like understand it ngStorage is a wrapper for localStorage so you have the same limits.

so , they have the same limits ? what about database , can I use it in saving some events ?

sure via sqlite, pouchdb, or in a json file…

but , i don’t know how can I use these sqlite, pouchdb, in saving some of my events :frowning:

add sqlite plugin --> intialize a db --> store and read data?

learn sql, read the sqlite tutorial or use ngCordova’s for a simple usage
http://ngcordova.com/docs/plugins/sqlite/

Hi @bengtler I tried to use this example of yours , but its not working , do you have any other examples other than this ?

I also tried this ngStorage but its not also working , Please I need your help ,

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>