Using Angularjs i am working on a mobile app where I need to clear the cookies after logout. The service I got to use is cookie authenticated, so after logout I need to clear them out.
For that I have tried traditional JS procedures to clear those cookies but didn't work.
After doing some more research on it I have added angular-cookies libary and used ngCookies to got access of the $cookies and $cookieStore in my scope. All the examples or SO posts I got says how to add/edit/delete new cookie using $cookies
and $cookieStore
.
But I am not setting the cookies by myself, its been set dynamically like JSESSIONID,SMSESSION..so on (a big string). When I try $cookieStore.get('JSESSIONID')
results undefined. AFAIK cookies are key value pairs, if yes then why I am getting undefined. (Am I wrong somewhere)
Is there anyway I can read all the cookies and reset/clear them using angular-cookies library.
Try this. It will iterate through stored cookies and remove them dynamically.
angular.forEach($cookies, function(value, key) {
$cookieStore.remove(key);
});
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.