如何更新angularjs 1中的$ localstorage数据

时间:2016-12-19 08:19:38

标签: angularjs

如何在更改任何内容时更新$ localStorage立即反映现在它只是存储数据到$ localStorage

function _setCurrentUser (user) {
  $localStorage.authUser = user;
  $localStorage.currentProfile = user;
  $rootScope.$broadcast(events.userChanged, user);
}

function getCurrentUser () {
  return $localStorage.authUser;
}

谢谢。

2 个答案:

答案 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