How can you work with cookies in Angular?

To work with Cookies, we can make use of the CookieService which is a part of the ngx-cookie-service module.

  • Install: npm install --save ngx-cookie-service
  • Include:
import { CookieService } from 'ngx-cookie-service';
  providers: [ CookieService ],
export class AppModule { }
  • Use:
constructor( private cookieService: CookieService ) { 
  this.cookieService.set( 'MyCookieKey', 'Hello There!' );
  this.cookieValue = this.cookieService.get('Test');

Angular Posted Nov 07, 2020

You can now show your support. 😊

We use cookies to provide you with a great user experience, analyze traffic and serve targeted promotions.   Learn More   Accept