use*_*513 4 angularjs angularjs-directive angularjs-scope ionic-framework
我正在尝试将数据保存在本地存储上,但收到错误$localStorage.getItem is not a function。实际上我正在使用 ionic 框架。我需要持久存储数据并从持久性获取数据。我使用 ngstorage.js 。我还包括该模块,但出现未定义的错误
在此行中出现错误
return $localStorage.getItem("list");
这是我的代码
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;
}
}
}
})();
Run Code Online (Sandbox Code Playgroud)
编辑
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);
}
Run Code Online (Sandbox Code Playgroud)
这是我对上述问题的想法
$localStorage.getItem("list")
可以使用$localStorage.list
.$localStorage.setItem("list",JSON.stringify(data));
你可以使用$localStorage.list = data