A lightweight Angular service for reading, setting, and deleting browser cookies with SSR support.
NGX Cookie Service is an Angular library that provides a service for managing browser cookies within Angular applications. It solves the problem of handling cookies in a type-safe, Angular-native way, offering methods to read, set, and delete cookies with support for modern attributes like sameSite and secure flags. It is designed to work with Angular 4.2+ up to the latest versions, including support for server-side rendering.
Angular developers who need to manage browser cookies for features like authentication tokens, user preferences, or session data in their applications, especially those using or considering server-side rendering.
Developers choose NGX Cookie Service for its minimal bundle size, seamless Angular integration, and dedicated SSR support. It replaces manual `document.cookie` manipulation or older libraries with a clean, injectable service that follows Angular's design patterns and includes comprehensive cookie attribute handling.
Angular (4.2+ ...12) service for cookies. Originally based on the ng2-cookies library.
Open-Awesome is built by the community, for the community. Submit a project, suggest an awesome list, or help improve the catalog on GitHub.
At only 1.3 KB minified, it has negligible impact on load times, as highlighted in the README's bundle size badge.
Provides full control over cookie attributes like expires, path, domain, secure, and sameSite, covering all standard browser cookie operations.
Designed for Angular's dependency injection, supporting both constructor injection and the inject() method, making it feel seamless in Angular apps.
Offers a separate ngx-cookie-service-ssr package for server-side rendering, ensuring cookies are accessible in Angular Universal environments.
Requires installing a separate package and modifying server.ts to provide REQUEST and RESPONSE objects, adding complexity compared to a single-package solution.
Only supports Angular 15.x.x and above, excluding older versions that might still be in use, as noted in the supported versions table.
Cannot set or delete cookies for other domains due to browser security, which might confuse developers expecting more flexibility, as mentioned in the API warnings.