Removing cookies in angularjs

4.1k views Asked by At

I have a problem removing cookies set to a particular domain.

When the cookies were set at say domain, a.b.io they were being deleted by this code.

$scope.clearStorage = function(){
            $localStorage.$reset();
            var cookies = $cookies.getAll();
            angular.forEach(cookies, function (v, k) {
                $cookies.remove(k);
            });

But when I set it to the domain b.io it isn't working. Tried to debug the the problem, the value of k is correct but $cookies.remove is simply not removing the cookie.

1

There are 1 answers

0
Ankit On

Try this code for delete cookie

$cookieStore.remove("userInfo");

EDIT: Since v1.4 $cookieStore has been deprecated (see docs), so from that version on you should use:

$cookies.remove("userInfo");

more details view this :https://stackoverflow.com/a/20988750/7255740