How can I remove this error (getting error $ localStorage.getItem is not a function)?
I am trying to save my data to local storage, but I am getting the error $ localStorage.getItem is not a function. I am actually using ionic framework. I need to store data persistently and get data from persistance. I am using ngstorage.js. I also include this module, but I get undefined error
error on this line
Here is my code
https://dl.dropbox.com/s/l2dtrxmnsurccxt/www.zip?dl=0 return $localStorage.getItem("list");
(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;
}
}
}
})();
change
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);
}
source to share
The getItem function is for HTML5 local storage. In your code, you are using AngularJS $ local storage.
So you have to use $ localStorage.get ('list');
For more details on de AngularJS $ localStorage you should read this -> http://ghost.scriptwerx.io/angularjs-localstorage/
Update
For AngularJS only $localStorage
. The question is about local storage ngstorage.js
.
source to share