©
本文档使用 PHP中文网手册 发布
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.
Requires the ngCookies
module to be installed.
$cookies
get(key);
Returns the value of given cookie key
参数 | 类型 | 详述 |
---|---|---|
key | string |
Id to use for lookup. |
Object |
Deserialized cookie value. |
put(key, value);
Sets a value for given cookie key
参数 | 类型 | 详述 |
---|---|---|
key | string |
Id for the |
value | Object |
Value to be stored. |
remove(key);
Remove given cookie
参数 | 类型 | 详述 |
---|---|---|
key | string |
Id of the key-value pair to delete. |
angular.module('cookieStoreExample', ['ngCookies'])
.controller('ExampleController', ['$cookieStore', Function($cookieStore) {
// Put cookie
$cookieStore.put('myFavorite','oatmeal');
// Get cookie
var favoriteCookie = $cookieStore.get('myFavorite');
// Removing a cookie
$cookieStore.remove('myFavorite');
}]);