NGX Cookie Service
An (AOT ready) Angular (4.2+) service for cookies. Originally based on the ng2-cookies library.
npm install ngx-cookie-service --save# oryarn add ngx-cookie-service
Add the cookie service to your
app.module.ts as a provider:
Then, import and inject it into a component:
check( name: string ): boolean;
Checks if a cookie with the given
name can be accessed or found.
get( name: string ): string;
Gets the value of the cookie with the specified
Returns a map of key-value pairs for cookies that can be accessed.
set( name: string, value: string, expires?: number | Date, path?: string, domain?: string, secure?: boolean ): void;
cookieService.set 'test', 'Hello World' ;
Sets a cookie with the specified
value. It is good practice to specify a path. If you are unsure about the path value, use
'/'. If no path or domain is explicitly defined, the current location is assumed.
delete( name: string, path?: string, domain?: string ): void;
Deletes a cookie with the specified
name. It is best practice to always define a path. If you are unsure about the path value, use
deleteAll( path?: string, domain?: string ): void;
Deletes all cookies that can currently be accessed. It is best practice to always define a path. If you are unsure about the path value, use
FAQ & Troubleshooting
Are you having any trouble with your integration or cookies in general? Check out our FAQ, maybe it will save you some headache.
This cookie service is brought to you by 7leads GmbH. We built it for one of our apps, because the other cookie packages we found were either not designed "the Angular way" or caused trouble during AOT compilation.
Check out the GitHub page for more.