-
Notifications
You must be signed in to change notification settings - Fork 734
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Angular操作cookies方法 #19
Labels
Comments
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
这是用Javascript写的方法去设置
这是用Javascript写的方法去读取
其实angular也有相应的方法去操作cookies的,加载这两个module的依赖文件
源码是这样的
$cookies[name] = value;
这个是angular设置cookies方法
$cookieStore
提供一个被session cookies支持的键值对(字符串-对象)存储。被存入和取出的对象将自动通过angular的toJson/fromJson进行序列化/反序列化。
$cookies
提供浏览器cookies的读/写访问操作。
这两个都要引入ngCookies模块才能使用,这个模块在1.4版本之后就有了
从源码中得知$cookieStore返回了三个方法get put remove 他们分别用toJson/fromJson进行序列化/反序列化
简单的写了几个例子来测试下
其实平时我们这样就可以把自己需要的cookies设置进去
$cookies.name = 'wscats';
但是当我们要设置一个有效时间的时候我们就用这样的方法把它设置进去
我们还可以进行删除等操作
$cookieStore.remove("name");
The text was updated successfully, but these errors were encountered: