0

I have used $cookieStore in angularjs with expiration time but expiration time is not working.

Look at this code...

var today = new Date();
var expiresValue = new Date(today);
//Set 'expires' option in (365 x 24 x 60 x 60) = 31536000 seconds = 1 year
expiresValue.setSeconds(today.getSeconds() + 31536000); 
// Setting a cookie
$cookieStore.put('STYPE', response.data.type, {'expires' : expiresValue});

How can i set expiration time in angularjs.

1
  • Can you please select the answer if it helped you Commented Feb 4, 2017 at 23:59

1 Answer 1

2

$cookieStore is depricated. Instead of using $cookieStore use $cookies

https://docs.angularjs.org/api/ngCookies/service/$cookies

$cookies.put('STYPE', response.data.type, {expires : expiresValue});
Sign up to request clarification or add additional context in comments.

1 Comment

Hi, I am using angular version 1.2.32 in my ancient project. There I am able to use put function with $cookieStore but not with $cookies. Could you please help me in understanding how I can set the expiry there? Currently the expiry is not being set even when I am using the below line: $cookieStore.put("newotpcookieobject", '7668787', { 'expires': expiresValue });

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.