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

$cookies and $cookieStore needs documentation and example #1320

Closed
JensRantil opened this issue Aug 30, 2012 · 17 comments
Closed

$cookies and $cookieStore needs documentation and example #1320

JensRantil opened this issue Aug 30, 2012 · 17 comments

Comments

@JensRantil
Copy link
Contributor

I can't find any official example whatsoever on cookie storage. $cookies also lacks API documentation.

@symblify
Copy link

@symblify
Copy link

I see what you mean though, there are no usage examples...

@gotoAndBliss
Copy link

I can't say there's any use to it until there is one.

+1 for Usage and examples.

@ninjacato
Copy link

Agree with @symblify and @gotoAndBliss.

+1 for Usage/Examples.

@sidecut
Copy link

sidecut commented Feb 9, 2013

I completely agree.

@Dynalon
Copy link

Dynalon commented Feb 11, 2013

+1

@ThomasDeutsch
Copy link

Is it right that $cookies is an abstraction of $cookieStore ? (like $resource is for $http)

I have 2 Examples

  1. with $cookieStore: http://jsfiddle.net/9jXF7/
  2. with $cookies: http://jsfiddle.net/5yFN5/

@chicoxyzzy
Copy link

@ThomasDeutsch $cookies can not store objects as a value so if you need to add/read an object to/from cookie you must convert it to/from JSON string. That's what $cookieStore.put() and $cookieStore.get() methods for. $cookies itself adds and deletes cookies on $digest

alonbardavid added a commit to alonbardavid/angular.js that referenced this issue Apr 20, 2013
$cookieStore service had no way to set cookie attributes (such as expires).
The api for $cookieStore.put and $cookieStore.remove now has a third argument-
options,which allows setting cookie attributes, or deleting cookies under a
specific path.
- to change the path and/or expiration date of a cookie, you can pass an
  options object as the third argument to cookies(name,value).
  the options object can override Path and Expires when adding a value.
  You can pass either path, expires,none or both.
- the path option is checked to be a string and be partial to window.location
  otherwise, the default path is used. (warning is logged)
- the expires option is checked to be a Date and in the future,
  otherwise no expiration is set. (warning is logged)
- you can now delete a cookie on a specific path by calling
  cookie(name,undefined,{path:x})

The $cookie service remains unchanged since supporting cookie attributes
would mean serious backward comptability issues.
Foundations were put in place to make supporting $cookie easier.
GENERIC TEST CHANGE:
To support checking cookie path, all unit-tests now run on path "/karma/tests"
Documentation was updated for both $cookie and $cookieStore with examples.

closes	angular#1786, angular#1320
BREAKING CHANGE: As part of the change, deleting a cookie  now deletes
   cookies set in multiple paths (and duplicate cookies if exists).
   Previously only cookies set in the / path were deleted.
   Since it is not intutive, if this change breaks someones code, it is
   probably as an accidental side-effect.
   It is reasonable to assume that most people actually wanted to delete the
   cookie even if it wasn't set in the same path (since they can see it).
   So while this is a breaking change, it fixes bad behaviour.
   If needed, you can delete the cookie in a specific path using $cookieStore.
@btford btford closed this as completed Aug 24, 2013
@btford
Copy link
Contributor

btford commented Aug 24, 2013

As part of our effort to clean out old issues, this issue is being automatically closed since it has been inactivite for over two months.

Please try the newest versions of Angular (1.0.8 and 1.2.0-rc.1), and if the issue persists, comment below so we can discuss it.

Thanks!

@joseym
Copy link

joseym commented Sep 5, 2013

lazy close!

@btford
Copy link
Contributor

btford commented Sep 5, 2013

@joseym would you like to submit a PR adding docs for this feature?

@joseym
Copy link

joseym commented Sep 7, 2013

Sure

Sent from my iPhone

On Sep 5, 2013, at 12:54 PM, Brian Ford [email protected] wrote:

@joseym would you like to submit a PR adding docs for this feature?


Reply to this email directly or view it on GitHub.

@KKrisu
Copy link

KKrisu commented Oct 10, 2013

+1 for example and usage

1 similar comment
@rasensio
Copy link

+1 for example and usage

@petebacondarwin
Copy link
Contributor

We will definitely merge a PR that contains runnable examples. In the meantime there are indeed basic usage examples at

https://docs.angularjs.org/api/ngCookies/service/$cookies#example
and
https://docs.angularjs.org/api/ngCookies/service/$cookieStore#example

@silviotroia
Copy link

+1 for example and usage

@comountainclimber
Copy link

You can check out my repo here for a working example if that helps at all...

Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Projects
None yet
Development

No branches or pull requests