MARKAND Bhatt
MARKAND Bhatt

Reputation: 2630

AngularJs Cookie : Share across multiple tabs

I am developing an angjs application. Used angjs 1.6.

Following is my code to create a cookie

$cookies.put('globals', $rootScope.globals);

When i open a new tab, I dont find this cookie variable "globals".

How to share cookies across multiple tabs?

Upvotes: 0

Views: 615

Answers (2)

Ram_T
Ram_T

Reputation: 8484

cookies are document specific. So, you are not getting in other tab. Please go for ngStorage or use localStorage

and one more thing is even you want to store non-prmitive data(object, array etc) in cookies/storage, you must stringfy before pushing and should be parsed after getting.

eg: $cookies.put('globals', JSON.stringify({name: 'My_name'}));

var myName = JSON.parse($cookies.get('globals'));

Upvotes: 2

Kyle Meenehan
Kyle Meenehan

Reputation: 115

Check if this helps you out:

$cookies.put('globals', $rootScope.globals, {domain: 'yourdomainhere'});

Upvotes: 0

Related Questions