Cookies in Angular
  • Reads 1
  • Votes 0
  • Parts 1
  • Time <5 mins
  • Reads 1
  • Votes 0
  • Parts 1
  • Time <5 mins
Ongoing, First published May 20, 2021
Cookies in Angular

Cookies are small packages of information that can be temporarily stored/saved by your browser and websites which are using cookies for multiple things.

Cookies are used in multiple requests and browser sessions and can store your account information used by authentication for example.

------------------------------------------------------------

==&gt; Size of Cookies: They are often not more than a few kilobytes per cookie.

-----------------------------------------------------------------

===&gt; How to install Cookies

We already have an NPM package for Angular called 'ngx-cookie-service' that can be used for cookie use.

npm install ngx-cookie-service

------------------------------------------------------

===&gt; How to use Cookies

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

2. import service in app.module.ts

   providers: [ CookieService ]

3. Inject Cookies service in constructor and set private variable

   constructor( private cookieService: CookieService ) { 

   this.cookieService.set( 'Test', 'Hello World' ); // Set Cookies Value

   this.cookieValue = this.cookieService.get('Test'); // Get Cookies Value

    }

-----------------------------------------------------------

===&gt; How to Delete Cookies

cookieService.delete('test'); // delete single data from cookies

cookieService.deleteAll();  // delete all cookies data

---------------------------------------------------------

===&gt; Method of Cookies

 1. Check :- Used to check cookies exits or not

 2. Set :- Used to set the value in cookies with name

 3. Get :- Used to return the single value of stored cookies name 

 4. Get All :- Used to return a value object of all cookies

 5. Delete :- Used to delete the single cookies value with the given name

 6. Delete All :- Used to delete all the cookies
All Rights Reserved
Sign up to add Cookies in Angular to your library and receive updates
or
#13method
Content Guidelines
You may also like
Slide 1 of 1
Wendizzy's Writer Room cover

Wendizzy's Writer Room

2 parts Ongoing

In this book, you'll get a behind the scenes look at how your favorite characters were born, my creative process, and the dirty details never before revealed. Tex's Camp Q&A: Come sit by the fire and ask me whatever you'd like. We can roast marshmallows, tell scary stories, and hang out in the comments like a big, happy family. Gator's Backstage Pass: A place full of secrets. Learn the-sometimes embarrassing-details on how my wildest scenes came to life, facts about the characters, the process, and myself.