angular 的本地存储

.factory('locals',['$window',function($window){
return{ //存储单个属性
set :function(key,value){
$window.sessionStorage[key]=value;
}, //读取单个属性
get:function(key,defaultValue){
return $window.sessionStorage[key] || defaultValue;
}, //存储对象,以JSON格式存储
setObject:function(key,value){
$window.sessionStorage[key]=JSON.stringify(value);
}, //读取对象
getObject: function (key) {
return JSON.parse($window.sessionStorage[key] || '{}');
}

}

locals 注入 controller

存储值

locals.set("key", value);

读取值

locals.get("key")
原文地址:https://www.cnblogs.com/xyc211/p/7375522.html