TypeScript icon, indicating that this package has built-in type declarations

1.3.2 • Public • Published


Table of contents:

Getting Started


You can install this package locally with npm. To get the latest stable version and update package.json file:

npm install ngx-cookie-monsters --save


CookieModule should be registered in the AppModule with forRoot() static method and with forChild() in the child modules.
These methods accepts CookieOptions objects as well. Leave it blank for the defaults.

import { NgModule }      from '@angular/core';
import { BrowserModule } from '@angular/platform-browser';

import { CookieModule } from 'ngx-cookie-monster';

import { AppComponent }  from './app.component';

  imports: [ BrowserModule, CookieModule.forRoot() ],
  declarations: [ AppComponent ],
  bootstrap: [ AppComponent ]
export class AppModule { }
import { Component } from '@angular/core';
import { NgxCookieMonsterService } from 'ngx-cookie-monster';

    selector: 'nom-nom-nom',
    template: '<h1>come to the dark side, we have cookies</h1>'

export class AppComponent { 
  constructor(private cookieService: NgxCookieMonsterService){}
  getCookie(key: string) {
    return this.cookieService.get(key);



Returns the value of given cookie key.

 * @param key ID for lookup.
 * @returns Raw cookie value as string.
get(key: string): string;


Returns a deserialized Object of given cookie.

 * @param key Id to use for lookup.
 * @returns deserialized cookied value.
getObject(key: string): Object;


Returns a key value object with all cookies

 * @returns All cookies
getAll(): any;


Evaluates if cookie exists

 * @param key ID for lookup
 * @returns cookie existance
exists(key: string): boolean;


Create a cookie for the given key

 * @param key ID
 * @param value stored raw.
 * @param (Optional) Options object.
create(key: string, value: string, options?: CookieOptions): void;


Create a cookie with an object of values

 * @param key ID
 * @param value stored serialized
 * @param (Optional) Options object.
createFromObject(key: string, value: Object, options?: CookieOptions): void;


Removes specific cookie

 * @param key ID for lookup
remove(key: string): void;


Removes all cookies.

removeAll(): void;


Options object should be a type of CookieOptions interface. The object may have following properties:

  • domain - {string} - The cookie will be available only for this domain and its sub-domains. For security reasons the user agent will not accept the cookie
  • path - {string} - The cookie will be available only for this path and its sub-paths. By default, this is the URL that appears in your <base> tag. if the current domain is not a sub-domain of this domain or equal to it.
  • expires - {string | number | Date} - String of the form "Wdy, DD Mon YYYY HH:MM:SS GMT", number of the form milliseconds or minutes or hours or a Date object indicating the exact date/time this cookie will expire.
  • secure - {boolean} - If true, then the cookie will only be available through a secured connection.
  • httpOnly - {boolean} - If true, then the cookie will be set with the HttpOnly flag, and will only be accessible from the remote server. Helps to prevent against XSS attacks.
  • storeUnencoded - {boolean} - If true, then the cookie value will not be encoded and will be stored as provided.
  • sameSite - {'none' | 'lax' | 'strict'} - If strict, then it will prevent the cookie from being sent by the brwoser to the target site in all cross-site browsing context. If lax, then it will provide a reasonable balance between security and usabillity for websites that want to maintain user's logged-in session after the user arrives from an external link.

Package Sidebar


npm i ngx-cookie-monsters

Weekly Downloads






Unpacked Size

291 kB

Total Files


Last publish


  • mikefox2k