如何在更改任何内容时更新$ localStorage立即反映现在它只是存储数据到$ localStorage
function _setCurrentUser (user) {
$localStorage.authUser = user;
$localStorage.currentProfile = user;
$rootScope.$broadcast(events.userChanged, user);
}
function getCurrentUser () {
return $localStorage.authUser;
}
谢谢。
答案 0 :(得分:1)
ID = 1
Client ------------> Server
ID = 1
Client <------------ Server
ID = 2
Client ------------> Server
X----ERROR----TimeOut
ID = 3
Client ------------> Server
ID = 2
Client <------------ Server
Client 3!=2 --> do not process, read again
ID = 3
Client <------------ Server
适用于添加/更新数据,setItem
适用于获取数据:
getItem
答案 1 :(得分:0)
你可以这样做:
$window.localStorage.setItem(key,value) //to store
$window.localStorage.getItem(key) //to retrieve
$window.localStorage.removeItem(key) //to remove