Skip to content
This repository was archived by the owner on Apr 12, 2024. It is now read-only.

feat(ngCookies): Additional parameters for $cookies service (domain, expires, secure) #6335

Closed
wants to merge 2 commits into from

Conversation

kbanman
Copy link

@kbanman kbanman commented Feb 19, 2014

This PR allows setting additional parameters on cookies created by $cookieStore. The changes are only on $browser to avoid major changes.

It seems to me the cookie logic could be somehow moved to $cookies, but I will leave that to someone else.

The expires parameter can be specified as integer seconds or as a Date object.

The parameters are set as follows:

angular.extend($browser.cookieOptions, {
  path: '/',
  domain: '.example.com',
  expires: 3600
});

Closes #590, and is an alternative PR to #2459

This PR allows setting additional parameters on cookies created by $cookieStore. The changes are only on $browser to avoid major changes.

It seems to me the cookie logic could be somehow moved to $cookies, but I will leave that to someone else.

The `expires` parameter can be specified as integer seconds or as a `Date` object.

The parameters are set as follows:
```
angular.extend($browser.cookieOptions, {
  path: '/',
  domain: '.example.com',
  expires: 3600
});
```

Closes #590, and is an alternative PR to #2459
@mary-poppins
Copy link

Thanks for the PR! Please check the items below to help us merge this faster. See the contributing docs for more information.

  • Uses the issue template (#6335)

If you need to make changes to your pull request, you can update the commit with git commit --amend.
Then, update the pull request with git push -f.

Thanks again for your help!

@kbanman kbanman added cla: yes and removed cla: no labels Feb 19, 2014
@luizfilipe
Copy link

Sweet need this feature, any info about what version this will be available?

@piotr-cz
Copy link

+1
There are almost no use cases of using cookies in SPA if it's expiry is session.
It's like a dev joke

return [
escape(name) + '=' + escape(value),
opt.expires ? '; expires=' + opt.expires.toUTCString() : '',
opt.path ? '; path=' + opt.path : '',

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I'd leave here the cookiePath as a fallback, so

  • not specifying the path has the same effect like before patch
  • this is IMHO good default value; it's easier to specify '' as a option then to pass the basePath every time we set cookie.
'; path=' + typeof opt.path === 'string' ? opt.path : cookiePath,

@lgalfaso
Copy link
Contributor

lgalfaso commented Jun 9, 2015

This PR is no longer valid given 92c366d

@lgalfaso lgalfaso closed this Jun 9, 2015
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Dependency injection of custom service into another custom service
7 participants