Yagiz Ozturk
Yagiz Ozturk

Reputation: 5428

Can't Delete Cookies with AngularJs

I cannot seem to delete cookies with Angularjs. What can be wrong.. Her is the code..

$scope.adminLogout = function(){
    $http({
        url: '/AdServerLongTail/adminapi/logout',
        method: "POST",
        dataType:"json",                                
        }).success(function (data, status, headers, config) {
            console.log("success");
            delete $cookies["username"]; 
            delete $cookies["JSESSIONID"];                
            $rootScope.welcome=null;
            $location.path("/admin");                
        }).error(function (data, status, headers, config) {
           console.log("error");               
   });          
}

html

<li><a href="#" ng-click="adminLogout()">LOGOUT</a></li>

Upvotes: 2

Views: 950

Answers (1)

Guy Nesher
Guy Nesher

Reputation: 1385

From the docs - cookies will get update at the end of the current $eval cycle (which is part of the $digest cycle). This means you might not see the cookies deleted straight away.

On a slightly different not the Angularjs Cookies library is quite broken and should not be used for any production ready project (for example you can't set expire time etc.)

Upvotes: 1

Related Questions