Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

how to remove this error (getting error $localStorage.getItem is not a function)?

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);
    }
like image 715
user944513 Avatar asked Oct 15 '25 14:10

user944513


1 Answers

These are my thought on the above issue

  • Think so you have missed out to inject the 'ngStorage' module.
  • Instead of $localStorage.getItem("list") you can use $localStorage.list.
  • Instead of $localStorage.setItem("list",JSON.stringify(data)); you can use $localStorage.list = data
like image 154
Nidhish Krishnan Avatar answered Oct 17 '25 08:10

Nidhish Krishnan