0

I'm writing Javascript code using Angular cookies which I will be using in two applications, one of which uses Angular 1.4 so I can use the $cookies getter and setter objects. But in the second application I'm using version 1.3 where I cant use the getter and setter objects. How can I write simple getter and setter cookies as the same object for both the versions?

For example:

$cookies.getObject("user.id");

$cookies.putObject("user.id", json.data, {
                            path: '/'
                        });
Functino
  • 1,939
  • 17
  • 25
rUI7999
  • 129
  • 1
  • 3
  • 20

1 Answers1

0

Angular took part a change in $cookie library from 1.3 to 1.4, so it's not possible to write same code that works in both version.

Step 1:

Angular 1.4:

$cookies.putObject("key", "value"); 
var value = $cookies.getObject("key");

Angular 1.3:

$cookies.key = "value";
var value = $cookies.key; 

or

var value = $cookies[key];

Step 2:

If you want to write same code in both version then u have to used Angular local storage, and it's performance is well.

Zahidur Rahman
  • 1,688
  • 2
  • 20
  • 30
  • I'm looking for a generic code which I can set and get cookies for both versions, as I said I'm using single JavaScript file in both versions.. I don't think of adding a local storage is a good idea – rUI7999 Apr 01 '16 at 12:37