Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

difference between $cookiestore and $cookies in angularjs

What is the difference between $cookiestore and $cookies in angularjs.

I saw the angularjs document.

$cookiestore and $cookies are doing same think, but the only difference is

$cookiestore- can objects put or retrieved from this storage are automatically serialized or deserialized by angular's toJson/fromJson .but $cookies- can't do this

Is the only one difference? or anything else?

like image 735
Ramesh Rajendran Avatar asked Apr 07 '15 05:04

Ramesh Rajendran


People also ask

What is cookies in AngularJS?

AngularJS provides ngCookies module for reading and writing browser cookies. To use it include the angular-cookies. js file and set ngCookies as a dependency in your angular app. This module provides two services for cookie management: $cookies and $cookieStore.

How can you set get and clear cookies in AngularJS?

In AngularJs, we need to use angular-cookies. js to set, get and clear the cookies. We need to include $cookies in your controller and it have to Get, Set and Clear method to get, set and clear cookies respectively. Angular has inbuilt directives named as ngCookies.

What is ngCookies?

module('app', ['ngCookies']); With that you're ready to get started! The ngCookies module provides a convenient wrapper for reading and writing browser cookies. See $cookies for usage.


1 Answers

I think the description of each in the documentation makes it quite clear:

$cookie just gives you access to cookies same as if you did by some other method.

$cookieStore uses cookies to make a key/value storage solution for you.

So if you are starting something new and want to persist key/value pairs use $cookieStore

If you want to use existing cookie solution - say read/write cookies from your existing server session system then use $cookie.

like image 107
Akshay Kalola Avatar answered Sep 18 '22 11:09

Akshay Kalola