All Projects → stevermeister → Ngx Cookie Service

stevermeister / Ngx Cookie Service

Licence: mit
Angular (4.2+ ...11) service for cookies. Originally based on the `ng2-cookies` library.

Programming Languages

typescript
32286 projects

Projects that are alternatives of or similar to Ngx Cookie Service

Ng2 Smart Table
Angular Smart Data Table component
Stars: ✭ 1,590 (+338.02%)
Mutual labels:  aot, aot-compilation, angular2
Egeo
EGEO is the open-source UI library used to build Stratio's UI. It includes UI Components, Utilities, Services and much more to build user interfaces quickly and with ease. The library is distributed in AoT mode.
Stars: ✭ 69 (-80.99%)
Mutual labels:  aot, aot-compilation, angular2
Ngx Meta
Dynamic page title & meta tags utility for Angular (w/server-side rendering)
Stars: ✭ 331 (-8.82%)
Mutual labels:  aot, angular2
nginx cookie flag module
Module for Nginx which allows to set the flags "HttpOnly", "secure" and "SameSite" for cookies.
Stars: ✭ 101 (-72.18%)
Mutual labels:  cookie, cookies
Zebra Cookie
A ridiculously small (~500 bytes minified) JavaScript API for writing, reading and deleting browser cookies
Stars: ✭ 15 (-95.87%)
Mutual labels:  cookie, cookies
ng-elm
Write Angular components in Elm.
Stars: ✭ 41 (-88.71%)
Mutual labels:  angular2, ngx
contao-cookiebar
Display the information about cookies on your Contao website
Stars: ✭ 27 (-92.56%)
Mutual labels:  cookie, cookies
angular2-cookie-law
Angular2+ component that provides a banner to inform users about cookie law
Stars: ✭ 38 (-89.53%)
Mutual labels:  angular2, cookies
cookies
Manage your cookies on client and server side (Angular Universal)
Stars: ✭ 40 (-88.98%)
Mutual labels:  cookie, cookies
Ngx Drag To Select
A lightweight, fast, configurable and reactive drag-to-select component for Angular 6 and beyond
Stars: ✭ 262 (-27.82%)
Mutual labels:  angular2, ngx
Cookies.js
Simple cookie framework with full Unicode support
Stars: ✭ 254 (-30.03%)
Mutual labels:  cookie, cookies
Angular2 Toaster
Angular2-toaster is an asynchronous, non-blocking Angular Toaster Notification library
Stars: ✭ 333 (-8.26%)
Mutual labels:  aot-compilation, angular2
PolishCookieConsent
Polish Cookie Consent is an extension, which automatically accepts privacy policy/GDPR on websites.
Stars: ✭ 17 (-95.32%)
Mutual labels:  cookie, cookies
ng-seed
Simple Angular seed project with commonly used features.
Stars: ✭ 12 (-96.69%)
Mutual labels:  angular2, aot
angular-gulp-starter
Simple dev/prod build for Angular (2+) using gulp, systemjs, rollup, ngc (AOT), scss, Visual Studio
Stars: ✭ 18 (-95.04%)
Mutual labels:  angular2, aot
awesome-angular
💖 A list of awesome Angular (2️⃣➕) resources
Stars: ✭ 61 (-83.2%)
Mutual labels:  angular2, ngx
CockyGrabber
C# library for the collection of browser information such as cookies, logins, and more
Stars: ✭ 46 (-87.33%)
Mutual labels:  cookie, cookies
Angularx Qrcode
Angular4/5/6/7/8/9/10/11 QRCode generator component library for QR Codes (Quick Response) with AOT support based on node-qrcode
Stars: ✭ 281 (-22.59%)
Mutual labels:  aot, aot-compilation
ng2-tooltip-directive
The tooltip is a pop-up tip that appears when you hover over an item or click on it.
Stars: ✭ 101 (-72.18%)
Mutual labels:  angular2, ngx
cookies
Convenient way to use cookies with PSR-7
Stars: ✭ 17 (-95.32%)
Mutual labels:  cookie, cookies

NGX Cookie Service

Angular 9 IVY Ready service for cookies. Originally based on the ng2-cookies library.

For versions <9, please use 2.3.0 version of library.

The experienced team behind Studytube will take care of our cookie service from now on.

Installation

npm install ngx-cookie-service --save

# or

yarn add ngx-cookie-service

Add the cookie service to your app.module.ts as a provider:

import { CookieService } from 'ngx-cookie-service';

@NgModule({
  ...
  providers: [ CookieService ],
  ...
})
export class AppModule { }

Then, import and inject it into a constructor:

constructor( private cookieService: CookieService ) { 
  this.cookieService.set( 'Test', 'Hello World' );
  this.cookieValue = this.cookieService.get('Test');
}

That's it!

Methods

check( name: string ): boolean;

const cookieExists: boolean = cookieService.check('test');

Checks if a cookie with the givenname can be accessed or found.

get( name: string ): string;

const value: string = cookieService.get('test');

Gets the value of the cookie with the specified name.

getAll(): {};

const allCookies: {} = cookieService.getAll();

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, sameSite?: 'Lax' | 'Strict' | 'None' ): void;

set( name: string, value: string, options?: { expires?: number | Date, path?: string, domain?: string, secure?: boolean, sameSite?: 'Lax' | 'None' | 'Strict'}): void;

cookieService.set( 'test', 'Hello World' );
cookieService.set( 'test', 'Hello World', {expires: 2, sameSite: 'Lax'});

Sets a cookie with the specified name and 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. sameSite defaults to Lax.

Important: For security reasons, it is not possible to define cookies for other domains. Browsers do not allow this. Read this and this StackOverflow answer for a more in-depth explanation.

Important: Browsers do not accept cookies flagged sameSite = 'None' if secure flag isn't set as well. CookieService will override the secure flag to true if sameSite='None'.

delete( name: string, path?: string, domain?: string, secure?: boolean, sameSite: 'Lax' | 'None' | 'Strict' = 'Lax'): void;

cookieService.delete('test');

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 '/'.

Important: For security reasons, it is not possible to delete cookies for other domains. Browsers do not allow this. Read this and this StackOverflow answer for a more in-depth explanation.

deleteAll( path?: string, domain?: string, secure?: boolean, sameSite: 'Lax' | 'None' | 'Strict' = 'Lax' ): void;

cookieService.deleteAll();

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

General tips

Checking out the following resources usually solves most of the problems people seem to have with this cookie service:

The following general steps are usually very helpful when debugging problems with this cookie service or cookies in general:

I am always getting a "token missing" or "no provider" error.

Package managers are a well known source of frustration. If you have "token missing" or "no provider" errors, a simple re-installation of your node modules might suffice:

rm -rf node_modules
yarn # or `npm install`

I have a problem with framework X or library Y. What can I do?

Please be aware that we cannot help you with problems that are out of scope. For example, we cannot debug a Symfony or Springboot application for you. In that case, you are better off asking the nice folks over at StackOverflow for help.

Do you support Angular Universal?

There is an issue for that. Check out this comment for more information about future support.

Opening issues

Please make sure to check out our FAQ before you open a new issue. Also, try to give us as much information as you can when you open an issue. Maybe you can even supply a test environment or test cases, if necessary?

Contributing

We are happy to accept pull requests or test cases for things that do not work. Feel free to submit one of those.

However, we will only accept pull requests that pass all tests and include some new ones (as long as it makes sense to add them, of course).

Author

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.

Contributors

Thanks to all contributors:

License

MIT

Note that the project description data, including the texts, logos, images, and/or trademarks, for each open source project belongs to its rightful owner. If you wish to add or remove any projects, please contact us at [email protected].