So normally I would use cookies
to parse data from one AngularJS
application to another, and then read those cookies before bootstrapping
my application.
所以通常我会使用cookie来解析从一个AngularJS应用程序到另一个AngularJS应用程序的数据,然后在引导我的应用程序之前读取这些cookie。
The problem with this approach is that the cookies have a size limit. And to get around this I thought about using $localstorage
from the ngStorage
library.
这种方法的问题是cookie有大小限制。为了解决这个问题,我想到了使用ngStorage库中的$ localstorage。
Now my problem is, how do I read the data stored in my $localstorage
before bootstrapping
my application, ie: in pure JavaScript
?
现在我的问题是,如何在引导我的应用程序之前读取存储在$ localstorage中的数据,即:在纯JavaScript中?
1 个解决方案
#1
5
It is really simple:
这很简单:
Store item:
商店项目:
localStorage.setItem('key', 'value');
Get Item:
获取物品:
localStorage.getItem('key');
You may want to store JSON in the storage, so you can always use JSON.stringify(var) in your set method, and JSON.parse(var) after your get.
您可能希望将JSON存储在存储中,因此您可以始终在set方法中使用JSON.stringify(var),并在get之后使用JSON.parse(var)。
#1
5
It is really simple:
这很简单:
Store item:
商店项目:
localStorage.setItem('key', 'value');
Get Item:
获取物品:
localStorage.getItem('key');
You may want to store JSON in the storage, so you can always use JSON.stringify(var) in your set method, and JSON.parse(var) after your get.
您可能希望将JSON存储在存储中,因此您可以始终在set方法中使用JSON.stringify(var),并在get之后使用JSON.parse(var)。