$cookieProvider

Configuration provider for $cookie service.

Description

Instance of CookieProvider for configuring the $cookie service.

It allows you to set global default options that will apply to all cookies created, updated, or removed using the $cookie service.

Properties


$cookieProvider.defaults

The defaults property defines global cookie settings. These values are applied to the $cookie service at initialization, and every cookie created through $cookie.put() or $cookie.putObject() will automatically inherit these defaults, unless overridden per-cookie.

  • Type: CookieOptions
  • Default: {}
  • Options:
    PropertyTypeDescription
    pathstringURL path the cookie belongs to. Defaults to the current path. Commonly set to '/' to make cookies accessible across the entire site.
    domainstringThe domain the cookie is visible to. Useful for subdomains (e.g., .example.com).
    expiresDateExpiration date. If omitted, the cookie becomes a session cookie (deleted on browser close).
    securebooleanIf true, the cookie is only sent over HTTPS.
    samesite"Strict" | "Lax" | "None"Controls cross-site cookie behavior. Required when secure: true and cross-site use is intended.
    httponlyNot supported.Browser JS cannot set HttpOnly cookies. This must be done on the server.

  • Example:
    angular
      .module('demo', [])
      .config([
        '$cookieProvider',
        /** @param {ng.CookieProvider} $cookieProvider */
        ($cookieProvider) => {
          $cookieProvider.defaults = {
            path: '/',
            secure: true,
            samesite: 'Lax'
          };
        }
      ]);
    

For service description, see $cookie.