Skip to content

ngx-cookie-service

A tiny Angular service to read, set and delete cookies. Typed, tree-shakable, and ready for server-side rendering.

This is the real library running on this page. Type a name, then reload the page.

Live demo
Terminal window
npm install ngx-cookie-service
import { inject } from '@angular/core';
import { CookieService } from 'ngx-cookie-service';
const cookieService = inject(CookieService);
cookieService.set('theme', 'dark', { expires: 30, path: '/' });
cookieService.get('theme'); // 'dark'
cookieService.delete('theme', { path: '/' });

Small and focused

One injectable service, about 1.3 kB minified and gzipped. No dependencies besides Angular.

Server-side rendering

ngx-cookie-service-ssr reads the request’s cookies and writes Set-Cookie headers while Angular renders on the server.

Safe defaults

SameSite=Lax by default, Secure forced where browsers require it, and unsafe paths or domains rejected with a warning.

App-wide configuration

Set default options once with provideCookieOptions(), and choose how values are encoded with provideCookieEncoding().