13

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

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.

I am using the angularJS and Twitter Bootstrap.

2 Answers 2

8

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);
}

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.

1
4

I've created module for AngularJS to solve this issue:

https://github.com/stevermeister/ng-biscuit

now you can simply set options:

cookieStore.put('x', 5, {domain: 'youdomain.com'})
4
  • what is minimum AngularJS version supported? Commented Aug 20, 2014 at 7:32
  • 1
    cookieStore is deprecated in later versions of Angular, I believe. It is in 1.4 +, at least.
    – demisx
    Commented Mar 24, 2015 at 21:47
  • I've already put "ng-biscuit" like deprecated, because cookieStore was fixed - github.com/angular/angular.js/commit/… Commented Mar 26, 2015 at 7:23
  • $cookieStore.put() does not have third parameter
    – Akim Kelar
    Commented Jul 20, 2016 at 9:15

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.