如何设置angularJS $饼干域 [英] how to set domain for angularJS $cookies

查看:124
本文介绍了如何设置angularJS $饼干域的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

这似乎 $饼干只允许设置键/值对。

It seems $cookies only allows to set the Key/Value pair.

不过,我需要设置域参数为好。我需要从网站的一个子域名设置Cookie,并从网站的所有子域使用它。

But i need to set the domain parameter as well. I need to set the cookie from one subdomain of website and use it from all subdomains of website.

我使用的是angularJS和Twitter的引导。

I am using the angularJS and Twitter Bootstrap.

推荐答案

目前这不是角(1.2.7)实现的。你可以看看angular.js行4348 - 相关code稍微降低:

Currently this is not implemented in angular (1.2.7). You may have a look at angular.js line 4348 - the relevant code a little bit reduced:

if (value === undefined) {
   // Delete the cookie
   rawDocument.cookie = escape(name) + 
          "=;path=" + cookiePath + ";expires=Thu, 01 Jan 1970 00:00:00 GMT";
} else {
   // set or update the cookie value
   rawDocument.cookie = escape(name) + '=' + escape(value) + ';path=' + cookiePath);
}

正如你所看到的;域=不包含XYZ。你必须写自己的CookieStore实现这一功能 - 但是这应该是很容易的。

as you can see the ;domain=XYZ is not included. You have to write your own cookiestore that implements this feature - but this should be very easy.

这篇关于如何设置angularJS $饼干域的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆