top button
Flag Notify
    Connect to us
      Site Registration

Site Registration

What is difference between $cookies and $cookieStore service?

0 votes
207 views
What is difference between $cookies and $cookieStore service?
posted Nov 27, 2017 by Latha

Share this question
Facebook Share Button Twitter Share Button LinkedIn Share Button

1 Answer

0 votes

$cookies - This service provides read/write access to browser's cookies.
If you want to use existing cookie solution, say read/write cookies from your existing server session system then
use $cookie.

var app=angular.module('cookiesExample', ['ngCookies']);
app.controller('ExampleController', function ($cookies) {
 // Retrieving a cookie
 var favoriteCookie = $cookies.myFavorite;
 // Setting a cookie
 $cookies.myFavorite = 'meal';
});

$cookiesStore - $cookieStore is a thin wrapper around $cookies. It provides a key-value (string-object) storage
that is backed by session cookies. The objects which are put or retrieved from this storage are automatically
serialized or deserialized by angular to JSON and vice versa.
If you are creating a new solution which will persist cookies based on key/value pairs, use $cookieStore.

var app=angular.module('cookieStoreExample', ['ngCookies']);
app.controller('ExampleController',function ($cookieStore) {
 // Put cookie
 $cookieStore.put('myFavorite', 'meal');
 // Get cookie
 var favoriteCookie = $cookieStore.get('myFavorite');
 // Removing a cookie
 $cookieStore.remove('myFavorite');
});
answer Nov 27, 2017 by Shivaranjini
...