|
| 1 | +--- |
| 2 | +title: $cookieProvider |
| 3 | +description: > |
| 4 | + Configuration provider for `$cookie` service. |
| 5 | +--- |
| 6 | + |
| 7 | +### Description |
| 8 | + |
| 9 | +Instance of [CookieProvider](../../../typedoc/classes/CookieProvider.html) for |
| 10 | +configuring the [$cookie](../../../docs/service/cookie) service. |
| 11 | + |
| 12 | +It allows you to set global default options that will apply to all cookies |
| 13 | +created, updated, or removed using the `$cookie` service. |
| 14 | + |
| 15 | +### Properties |
| 16 | + |
| 17 | +--- |
| 18 | + |
| 19 | +#### $cookieProvider.defaults |
| 20 | + |
| 21 | +The [defaults](../../../typedoc/classes/CookieProvider.html#defaults) property |
| 22 | +defines global cookie settings. These values are applied to the `$cookie` |
| 23 | +service at initialization, and every cookie created through `$cookie.put()` or |
| 24 | +`$cookie.putObject()` will automatically inherit these defaults, unless |
| 25 | +overridden per-cookie. |
| 26 | + |
| 27 | +- **Type:** [CookieOptions](../../../typedoc/interfaces/CookieOptions.html) |
| 28 | +- **Default:** `{}` |
| 29 | +- | **Options:** | Property | Type | Description | |
| 30 | + | ------------ | -------- | ----------------------------------------------- | ----------- | |
| 31 | + | **path** | `string` | URL path the cookie belongs to. Defaults to the | |
| 32 | + |
| 33 | + current path. Commonly set to `'/'` to make cookies accessible across the |
| 34 | + entire site. | | **domain** | `string` | The domain the cookie is visible to. |
| 35 | + Useful for subdomains (e.g., `.example.com`). | | **expires** | `Date` | |
| 36 | + Expiration date. If omitted, the cookie becomes a _session cookie_ (deleted on |
| 37 | + browser close). | | **secure** | `boolean` | If `true`, the cookie is only |
| 38 | + sent over HTTPS. | | **samesite** | `"Strict" \| "Lax" \| "None"` | Controls |
| 39 | + cross-site cookie behavior. Required when `secure: true` and cross-site use is |
| 40 | + intended. | | **httponly** | _Not supported._ | Browser JS cannot set |
| 41 | + `HttpOnly` cookies. This must be done on the server. | |
| 42 | + |
| 43 | +- **Example:** |
| 44 | + ```js |
| 45 | + angular.module('demo', []).config(($cookieProvider) => { |
| 46 | + $cookieProvider.defaults = { |
| 47 | + path: '/', |
| 48 | + secure: true, |
| 49 | + samesite: 'Lax', |
| 50 | + }; |
| 51 | + }); |
| 52 | + ``` |
| 53 | + |
| 54 | +--- |
| 55 | + |
| 56 | +For service description, see [$cookie](../../../docs/service/cookie). |
0 commit comments