blob: 2bd0058519473473c2c4028027ede984b5ebc609 (
plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
|
'use strict';
/**
* @ngdoc object
* @name angular.module.NG.$cookieStore
* @requires $cookies
*
* @description
* Provides a key-value (string-object) storage, that is backed by session cookies.
* Objects put or retrieved from this storage are automatically serialized or
* deserialized by angular's toJson/fromJson.
* @example
*/
function $CookieStoreProvider(){
this.$get = ['$cookies', function($cookies) {
return {
/**
* @ngdoc method
* @name angular.module.NG.$cookieStore#get
* @methodOf angular.module.NG.$cookieStore
*
* @description
* Returns the value of given cookie key
*
* @param {string} key Id to use for lookup.
* @returns {Object} Deserialized cookie value.
*/
get: function(key) {
return fromJson($cookies[key]);
},
/**
* @ngdoc method
* @name angular.module.NG.$cookieStore#put
* @methodOf angular.module.NG.$cookieStore
*
* @description
* Sets a value for given cookie key
*
* @param {string} key Id for the `value`.
* @param {Object} value Value to be stored.
*/
put: function(key, value) {
$cookies[key] = toJson(value);
},
/**
* @ngdoc method
* @name angular.module.NG.$cookieStore#remove
* @methodOf angular.module.NG.$cookieStore
*
* @description
* Remove given cookie
*
* @param {string} key Id of the key-value pair to delete.
*/
remove: function(key) {
delete $cookies[key];
}
};
}];
}
|