{"id":13424221,"url":"https://github.com/stevermeister/ngx-cookie-service","last_synced_at":"2026-03-15T13:57:34.065Z","repository":{"id":37835429,"uuid":"88862180","full_name":"stevermeister/ngx-cookie-service","owner":"stevermeister","description":"Angular (4.2+ ...12) service for cookies. Originally based on the `ng2-cookies` library.","archived":false,"fork":false,"pushed_at":"2025-04-19T20:10:31.000Z","size":3085,"stargazers_count":561,"open_issues_count":3,"forks_count":92,"subscribers_count":17,"default_branch":"master","last_synced_at":"2025-05-05T12:21:46.097Z","etag":null,"topics":["angular","angular-service","angular2","aot","aot-compatible","aot-compilation","cookie","cookie-service","cookies","ng","ngx","typescript"],"latest_commit_sha":null,"homepage":"https://www.npmjs.com/package/ngx-cookie-service","language":"TypeScript","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":"mit","status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/stevermeister.png","metadata":{"files":{"readme":"README.md","changelog":"CHANGELOG.md","contributing":"CONTRIBUTING.md","funding":"FUNDING.yml","license":"LICENSE","code_of_conduct":"CODE_OF_CONDUCT.md","threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":"SECURITY.md","support":null,"governance":null,"roadmap":null,"authors":null,"dei":null,"publiccode":null,"codemeta":null,"zenodo":null},"funding":{"open_collective":"ngx-cookie-service"}},"created_at":"2017-04-20T12:18:00.000Z","updated_at":"2025-04-19T20:10:35.000Z","dependencies_parsed_at":"2024-01-01T05:07:44.465Z","dependency_job_id":"4996a503-6cb6-43bf-bf85-8825adfab753","html_url":"https://github.com/stevermeister/ngx-cookie-service","commit_stats":{"total_commits":311,"total_committers":23,"mean_commits":"13.521739130434783","dds":0.427652733118971,"last_synced_commit":"e89331dedba1d227560ed54cdbae2f5eb0b004eb"},"previous_names":[],"tags_count":51,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/stevermeister%2Fngx-cookie-service","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/stevermeister%2Fngx-cookie-service/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/stevermeister%2Fngx-cookie-service/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/stevermeister%2Fngx-cookie-service/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/stevermeister","download_url":"https://codeload.github.com/stevermeister/ngx-cookie-service/tar.gz/refs/heads/master","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":254040638,"owners_count":22004585,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2022-07-04T15:15:14.044Z","host_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub","repositories_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories","repository_names_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repository_names","owners_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners"}},"keywords":["angular","angular-service","angular2","aot","aot-compatible","aot-compilation","cookie","cookie-service","cookies","ng","ngx","typescript"],"created_at":"2024-07-31T00:00:50.335Z","updated_at":"2026-01-28T03:15:24.188Z","avatar_url":"https://github.com/stevermeister.png","language":"TypeScript","funding_links":["https://opencollective.com/ngx-cookie-service"],"categories":["Инструменты","Third Party Components"],"sub_categories":["Cookies"],"readme":"# NGX Cookie Service\n\n\u003cp align=\"center\"\u003e\n\n\n\n[![Build](https://github.com/stevermeister/ngx-cookie-service/actions/workflows/ci.yml/badge.svg)](https://github.com/stevermeister/ngx-cookie-service/actions/workflows/ci.yml)\n![npm bundle size](https://img.shields.io/bundlephobia/minzip/ngx-cookie-service) \n\u003ca href=\"https://www.npmjs.com/ngx-cookie-service\"\u003e\n\u003cimg src=\"https://img.shields.io/npm/v/ngx-cookie-service.svg?logo=npm\u0026logoColor=fff\u0026label=NPM+package\u0026color=limegreen\" alt=\"Ngx Cookie Service on npm\" /\u003e\n\u003c/a\u003e\n\u003ca href=\"https://gitter.im/ngx-cookie-service/community\"\u003e\n\u003cimg src=\"https://badges.gitter.im/ngx-cookie-service/community.svg\" alt=\"Chat in Gitter\" /\u003e\n\u003c/a\u003e\n[![ngx-cookie-service channel on discord](https://img.shields.io/discord/873021904708059177.svg?style=flat-square)](https://discord.gg/N3xc4Jfb)\n\n\u003c/p\u003e\n\nAngular service to read, set and delete browser cookies. Originally based on\nthe [ng2-cookies](https://www.npmjs.com/package/ng2-cookies) library. This service is lightweight, and its bundle size is **1.3 Kb** to ensure fast loading times and optimal performance.\n\n## Installation\n\n```bash\nnpm i ngx-cookie-service\n\n# or\n\nyarn add ngx-cookie-service\n```\n\n## Demo\n\nCooke Service Demo: https://stackblitz.com/~/github.com/pavankjadda/ngx-cookie-service-demo\n\nSSR Cookie Service Demo: [https://ngx-cookie-service-ssr-demo.netlify.app/](https://ngx-cookie-service-ssr-demo.netlify.app/)\n\n\n## Usage\n\n1. In standalone components, import the CookieService directly into the component\n\n   ```typescript\n   import { CookieService } from 'ngx-cookie-service';\n   import { Component } from '@angular/core';\n\n   @Component({\n     selector: 'my-component',\n     template: `\u003ch1\u003eHello World\u003c/h1\u003e`,\n     providers: [CookieService],\n   })\n   export class HelloComponent {\n     constructor(private cookieService: CookieService) {\n       this.cookieService.set('token', 'Hello World');\n       console.log(this.cookieService.get('token'));\n     }\n   }\n   ```\n\n2. You can also use `inject()` method in v14+ to inject the service into the component\n\n   ```typescript\n   import { CookieService } from 'ngx-cookie-service';\n   import { Component, inject } from '@angular/core';\n\n   @Component({\n     selector: 'my-component',\n     template: `\u003ch1\u003eHello World\u003c/h1\u003e`,\n     providers: [CookieService],\n   })\n   export class HelloComponent {\n     cookieService = inject(CookieService);\n\n     constructor() {\n       this.cookieService.set('token', 'Hello World');\n       console.log(this.cookieService.get('token'));\n     }\n   }\n   ```\n\n## Server Side Rendering\n\nNgx Cookie Service supports Server Side Rendering (SSR) via dedicated\nlibrary [ngx-cookie-service-ssr](https://www.npmjs.com/package/ngx-cookie-service-ssr).\nOnly install `ngx-cookie-service-ssr` library (and skip `ngx-cookie-service`) for SSR\n\n1. Install the library using below command\n\n   ```shell\n       npm install ngx-cookie-service-ssr --save\n\n       # or\n\n       yarn add ngx-cookie-service-ssr\n   ```\n\n2. By default, browser cookies are not\n   available in SSR because `document` object is not available. To overcome this, navigate to `server.ts` file in your\n   SSR\n   project, and replace the following code\n   \n   ```typescript\n   server.get('*', (req, res) =\u003e {\n     res.render(indexHtml, { req, providers: [{ provide: APP_BASE_HREF, useValue: req.baseUrl }] });\n   });\n   ```\n\nwith this\n\n```typescript\nserver.get('*', (req, res) =\u003e {\n  res.render(indexHtml, {\n    req,\n    providers: [\n      { provide: APP_BASE_HREF, useValue: req.baseUrl },\n      { provide: 'REQUEST', useValue: req },\n      { provide: 'RESPONSE', useValue: res },\n    ],\n  });\n});\n```\n\n3. This will make sure the cookies are available in `REQUEST` object, and the `ngx-cookie-service-ssr` can\n   use `REQUEST.cookies` to access the\n   cookies in SSR. Then proceed to use `ngx-cookie-service` as usual.\n4. See the [sample repo](https://github.com/pavankjadda/angular-ssr-docker) for more details.\n\n## Supported Versions\nWe follow angular [LTS versions](https://angular.dev/reference/versions#actively-supported-versions). The latest version of the library supports Angular 19.x.x. Angular 14.x.x or below is not supported.\n\n| Angular Version        | Supported Version |\n|------------------------|-------------------|\n| 19.x.x                 | 19.x.x            |\n| 18.x.x                 | 18.x.x            |\n| 17.x.x                 | 17.x.x            |\n| 16.x.x                 | 16.x.x            |\n| 15.x.x                 | 15.x.x            |\n\n# API\n\n## check( name: string ): boolean;\n\n```typescript\nconst cookieExists: boolean = cookieService.check('test');\n```\n\nChecks if a cookie with the given`name` can be accessed or found.\n\n## get( name: string ): string;\n\n```typescript\nconst value: string = cookieService.get('test');\n```\n\nGets the value of the cookie with the specified `name`.\n\n## getAll(): {};\n\n```typescript\nconst allCookies: {} = cookieService.getAll();\n```\n\nReturns a map of key-value pairs for cookies that can be accessed.\n\n## set( name: string, value: string, expires?: number | Date, path?: string, domain?: string, secure?: boolean, sameSite?: 'Lax' | 'Strict' | 'None' ): void;\n\n## set( name: string, value: string, options?: { expires?: number | Date, path?: string, domain?: string, secure?: boolean, sameSite?: 'Lax' | 'None' | 'Strict'}): void;\n\n```typescript\ncookieService.set('test', 'Hello World');\ncookieService.set('test', 'Hello World', { expires: 2, sameSite: 'Lax' });\n```\n\nSets a cookie with the specified `name` and `value`. It is good practice to specify a path. If you are unsure about the\npath value, use `'/'`. If no path or domain is explicitly defined, the current location is assumed. `sameSite` defaults\nto `Lax`.\n\n**Important:** For security reasons, it is not possible to define cookies for other domains. Browsers do not allow this.\nRead [this](https://stackoverflow.com/a/1063760) and [this](https://stackoverflow.com/a/17777005/1007003) StackOverflow\nanswer for a more in-depth explanation.\n\n**Important:** Browsers do not accept cookies flagged sameSite = 'None' if secure flag isn't set as well. CookieService\nwill override the secure flag to true if sameSite='None'.\n\n## delete( name: string, path?: string, domain?: string, secure?: boolean, sameSite: 'Lax' | 'None' | 'Strict' = 'Lax'): void;\n\n```typescript\ncookieService.delete('test');\n```\n\nDeletes a cookie with the specified `name`. It is best practice to always define a path. If you are unsure about the\npath value, use `'/'`.\n\n**Important:** For security reasons, it is not possible to delete cookies for other domains. Browsers do not allow this.\nRead [this](https://stackoverflow.com/a/1063760) and [this](https://stackoverflow.com/a/17777005/1007003) StackOverflow\nanswer for a more in-depth explanation.\n\n## deleteAll( path?: string, domain?: string, secure?: boolean, sameSite: 'Lax' | 'None' | 'Strict' = 'Lax' ): void;\n\n```typescript\ncookieService.deleteAll();\n```\n\nDeletes all cookies that can currently be accessed. It is best practice to always define a path. If you are unsure about\nthe path value, use `'/'`.\n\n# FAQ\n\n## General tips\n\nChecking out the following resources usually solves most of the problems people seem to have with this cookie service:\n\n- [article about cookies in general @MDN](https://developer.mozilla.org/en-US/docs/Web/HTTP/Cookies) (recommended read!)\n- [common localhost problems @StackOverflow](https://stackoverflow.com/questions/1134290/cookies-on-localhost-with-explicit-domain)\n- [problems with secure cookies @StackOverflow](https://stackoverflow.com/questions/8064318/how-to-read-a-secure-cookie-using-javascript)\n- [how do browser cookie domains work? @StackOverflow](https://stackoverflow.com/questions/1062963/how-do-browser-cookie-domains-work)\n- [get cookies from different paths](https://github.com/7leads/ngx-cookie-service/issues/7#issuecomment-351321518)\n\nThe following general steps are usually very helpful when debugging problems with this cookie service or cookies in\ngeneral:\n\n- check out if there are any [open](https://github.com/stevermeister/ngx-cookie-service/issues)\n  or [closed](https://github.com/stevermeister/ngx-cookie-service/issues?q=is%3Aissue+is%3Aclosed) issues that answer\n  your question\n- check out the actual value(s) of `document.cookie`\n- does it work if you use `document.cookie` manually (i.e. in a console of your choice)?\n- set explicit paths for your cookies\n- [explain to your local rubber duck why your code should work and why it (probably) does not](https://en.wikipedia.org/wiki/Rubber_duck_debugging)\n\n# I am always getting a \"token missing\" or \"no provider\" error.\n\nPackage managers are a well known source of frustration. If you have \"token missing\" or \"no provider\" errors, a simple\nre-installation of your node modules might suffice:\n\n```\nrm -rf node_modules\nyarn # or `npm install`\n```\n\n## I have a problem with framework X or library Y. What can I do?\n\nPlease be aware that we cannot help you with problems that are out of scope. For example, we cannot debug a Symfony or\nSpringboot application for you. In that case, you are better off asking the nice folks over\nat [StackOverflow](https://stackoverflow.com/) for help.\n\n## Do you support Angular Universal?\n\nThere is an [issue](https://github.com/7leads/ngx-cookie-service/issues/1) for that. Check\nout [this comment](https://github.com/7leads/ngx-cookie-service/issues/1#issuecomment-361150174) for more information\nabout future support.\n\n# Opening issues\n\nPlease make sure to check out our FAQ before you open a new issue. Also, try to give us as much information as you can\nwhen you open an issue. Maybe you can even supply a test environment or test cases, if necessary?\n\n# Contributing\n\nWe are happy to accept pull requests or test cases for things that do not work. Feel free to submit one of those.\n\nHowever, we will only accept pull requests that pass all tests and include some new ones (as long as it makes sense to\nadd them, of course).\n\n- [Open a new pull request](https://github.com/stevermeister/ngx-cookie-service/compare)\n\n# Author\n\nThis cookie service is brought to you by [7leads GmbH](http://www.7leads.org/). We built it for one of our apps, because\nthe other cookie packages we found were either not designed \"the Angular way\" or caused trouble during AOT compilation.\n\n# Contributors\n\nThanks to all contributors:\n\n- [Pavan Kumar Jadda](https://github.com/pavankjadda)\n- [paroe](https://github.com/paroe)\n- [CunningFatalist](https://github.com/CunningFatalist)\n- [kthy](https://github.com/kthy)\n- [JaredClemence](https://github.com/JaredClemence)\n- [flakolefluk](https://github.com/flakolefluk)\n- [mattbanks](https://github.com/mattbanks)\n- [DBaker85](https://github.com/DBaker85)\n- [mattlewis92](https://github.com/mattlewis92)\n- [IceBreakerG](https://github.com/IceBreakerG)\n- [rojedalopez](https://github.com/rojedalopez)\n- [Nikel163](https://github.com/Nikel163)\n\n# License\n\n[MIT](https://github.com/stevermeister/ngx-cookie-service/blob/master/LICENSE)\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fstevermeister%2Fngx-cookie-service","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fstevermeister%2Fngx-cookie-service","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fstevermeister%2Fngx-cookie-service/lists"}