ngx-cookie-service
An injectable Angular service for reading, writing, and deleting browser cookies.
ngx-cookie-service
AngularAn injectable Angular service for reading, writing, and deleting browser cookies.
Fit
Bundle (gzip)
1.3 kB
2.8 kB raw
Install size includes transitive dependencies. Bundle size is gzipped browser payload.
Freshness
The Problem
Angular has no built-in abstraction for cookies, so components end up touching document.cookie directly — which is awkward to parse, hard to test, and unsafe to use during server-side rendering.
What It Does
ngx-cookie-service wraps cookie access in an injectable, tree-shakeable Angular service with get, set, check, and delete methods, keeping cookie logic out of your components and easy to mock in tests.
Installation
npm install ngx-cookie-serviceUsage Example
import { Component, inject } from "@angular/core";
import { CookieService } from "ngx-cookie-service";
@Component({ selector: "app-root", template: "<p>{{ theme }}</p>" })
export class AppComponent {
private cookies = inject(CookieService);
theme = this.cookies.get("theme") || "light";
setDark() {
this.cookies.set("theme", "dark", { path: "/" });
}
}Related packages
Angular Component Dev Kit — a set of behavior primitives for building accessible, high-quality UI components without prescribing any visual style.
@angular/materialAngularOfficial Material Design component library for Angular — 30+ accessible, themeable UI components built for Angular's ecosystem.
@ng-bootstrap/ng-bootstrapAngularAngular widgets built from scratch using Bootstrap CSS — no jQuery, no Popper.js, just pure Angular components.
ng-zorro-antdAngularEnterprise-grade UI component library for Angular based on Ant Design — 60+ production-ready components with a polished design system.
@ngneat/until-destroyAngularAutomatic RxJS subscription cleanup for Angular components — no more manual unsubscribe logic in ngOnDestroy.