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)
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:
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
})
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.
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>