I'm working on a page with some FAQs, and i'm using angular localstorage to save data. Then i'm uploading all my files to a server, to share with other people. When I do this I loose the data, and get it.It's the first time i'm uploading, so it can't be there. Then I insert some data, and it works fine, even if i close browser and open it again, my data is there.
But then when I upload again my .html file, to the server, i loose it again. It's the same url, same html page, but some how the data in angular localstorage kind a gets reseted.
I'm new at angular, and i'm using localstorage for the first time. I've search for this issue but have not found any tips.
How can i keep data in localstorage?
My code in angular module is:
var app = angular.module('WikiCTTXApp',['ngSanitize', 'ngStorage']);
app.controller('InfoInterController',function($scope, $localStorage,$sessionStorage){
$scope.$storage = $localStorage; $scope.InfoInter = $localStorage.InfoInter; $scope.newInfoInter = {}; $scope.addInfoInter=function(){ /* AD(added later): I added this line to test and initialize the variable and my issue disapeard */ if (typeof($scope.InfoInter) == 'undefined'){$scope.InfoInter=[]}; $scope.InfoInter.push($scope.newInfoInter); $scope.newInfoInter = {}; $scope.save(); }; $scope.remove = function(item) { var index = $scope.InfoInter.indexOf(item); $scope.InfoInter.splice(item, 1); }; $scope.save = function() { $localStorage.InfoInter = $scope.InfoInter; }; $scope.load = function() { $scope.InfoInter = $localStorage.InfoInter; }; });
getandsetthelocalStoragedata.