0

Hi I am developing angularjs application. I am using cookies in my application. On logout i want to remove all the cookies i set. I am using $cookieStore to set cookie value. Is there any way to delete all cookies? I have used below function.

 $scope.logout=function()
    {
        debugger;
        angular.forEach($cookies, function (v, k) {
            $cookieStore.remove(k);
        });
    }

I am not sure what is $cookies in the above code? When i use above code i have below error also. $cookies is not defined. May i know is there any way to delete all cookies in one shot instead of removing one by one? Any help would be appreciated. Thank you.

Niranjan Godbole
  • 2,135
  • 7
  • 43
  • 90
  • Possible duplicate of [How to remove all cookies in Angularjs?](https://stackoverflow.com/questions/26607856/how-to-remove-all-cookies-in-angularjs) – papakias Jul 21 '17 at 08:00
  • Hi papakias. thank you for you reference. May i know what is $cookies in the above piece of code or from the link you provided? – Niranjan Godbole Jul 21 '17 at 08:01

1 Answers1

0

$cookies is angular define service. so you need to inject this to the controller in order to use it. Also $cookieStore is deprecated since angular 1.4. So use $cookies.remove(k) instead of $cookieStore.remove(k);.

angular.forEach($cookies, function (v, k) {
   $cookies.remove(k);
 });
Sachila Ranawaka
  • 39,756
  • 7
  • 56
  • 80