I am trying to save my data on local storage but I am getting error $localStorage.getItem is not a function.Actually i am using ionic framework .I need to store data in persistance and get data from persistance .I use ngstorage.js .I also include that module , but getting the undefined error
getting error in this line
return $localStorage.getItem("list");
Here is my code
https://dl.dropbox.com/s/l2dtrxmnsurccxt/www.zip?dl=0
(function(){
'use strict';
angular.module('app.stationselect').factory('stationListDownload', stationListDownload);
stationListDownload.$inject=['$http','$localStorage']
function stationListDownload($http,$localStorage){
var list;
return {
getDownloadList: function(){
return $http.get("http://caht.firstrail.com/FGRailApps/jservices/rest/stationList");
},
getlist :function(){
return $localStorage.getItem("list");
},
setList :function (list){
this.list=list;
}
}
}
})();
edit
var list= stationListDownload.getlist();
if(list==null ||typeof list=='undefined' ){
stationListDownload.getDownloadList().then(function(data){
$scope.loadingIndicator.hide();
console.log("success")
$localStorage.setItem("list",JSON.stringify(data));
},function(error){
console.log("error")
})
}else {
console.log('else condition')
cosole.log(list);
}
These are my thought on the above issue
$localStorage.getItem("list")
you can use $localStorage.list
.$localStorage.setItem("list",JSON.stringify(data));
you can use $localStorage.list = data
For the ngStorage library, there isn't a getItem()
method, you simply read and write using standard object member access:
getlist :function(){
return $localStorage.list;
},
setList :function (list){
$localStorage.list=list;
}
The Function getItem is for the HTML5 localStorage. In your Code, you use the AngularJS $localStorage.
So you should use $localStorage.get('list');
For more Information about de AngularJS $localStorage you should read this -> http://ghost.scriptwerx.io/angularjs-localstorage/
Update
Only for AngularJS $localStorage
. The question is for the ngstorage.js
localStorage.