ngStorage not working properly when redirect using window.location

谁说我不能喝 提交于 2019-12-05 16:01:32
Blackus

This problem has been answered here by @claireablani. It seems that page reloading occurs before modification on localStorage has been applied.

You can use a fork of ngStorage library by @raynode (Github here, not available on bower) which add a $save() method to ensure modification had been applied.

$localStorage.$apply();

did the trick for me

thanks to this github issue comment

var setLocalStorage = function (token, uname)
{
$localStorage.token = token;
$localStorage.name = uname;

}
$timeout(setLocalStorage(token, userForm.uname), 500);

Module Used : ngStorage

OR

$localStorage.apply(); //Just after adding values in localstorage use this. No timeout required.

I also ran into this issue. I was trying to update localStorage in a service and it didn't seem to work. At least not inside a promise. Tried $localStorage.$apply() and $timeout there, but it didn't work. I had to move the code inside my controller to make this work.

$scope.$localStorage.myVar = 'test';
$scope.$localStorage.$apply();
$state.go('app.home');
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!