Provides read/write access to browser's cookies.
$cookies
exposed properties that represented the current browser cookie values. In version 1.4, this behavior has changed, and $cookies
now provides a standard api of getters, setters etc. Requires the ngCookies
module to be installed.
Returns the value of given cookie key
Param | Type | Details |
---|---|---|
key | string | Id to use for lookup. |
string |
Raw cookie value. |
Returns the deserialized value of given cookie key
Param | Type | Details |
---|---|---|
key | string | Id to use for lookup. |
Object |
Deserialized cookie value. |
Returns a key value object with all the cookies
Object |
All cookies |
Sets a value for given cookie key
Param | Type | Details |
---|---|---|
key | string | Id for the |
value | string | Raw value to be stored. |
options (optional) | Object | Options object. See $cookiesProvider.defaults |
Serializes and sets a value for given cookie key
Param | Type | Details |
---|---|---|
key | string | Id for the |
value | Object | Value to be stored. |
options (optional) | Object | Options object. See $cookiesProvider.defaults |
Remove given cookie
Param | Type | Details |
---|---|---|
key | string | Id of the key-value pair to delete. |
options (optional) | Object | Options object. See $cookiesProvider.defaults |
angular.module('cookiesExample', ['ngCookies']) .controller('ExampleController', ['$cookies', function($cookies) { // Retrieving a cookie var favoriteCookie = $cookies.get('myFavorite'); // Setting a cookie $cookies.put('myFavorite', 'oatmeal'); }]);
© 2010–2016 Google, Inc.
Licensed under the Creative Commons Attribution License 4.0.
https://code.angularjs.org/1.4.14/docs/api/ngCookies/service/$cookies