How to clear cookies in angular.js

馋奶兔 提交于 2019-12-01 02:22:35
michael

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");

I have found some answer

Option 1

delete $cookies["userInfo"]

option 2

 .controller('LogoutCtrl', ['$scope',  '$cookies', function ($scope,$cookies) {

    $cookies.userInfo = undefined;

}]);
user4231636
angular.forEach($cookies, function (cookie, key) {
    if (key.indexOf('NAV-') > -1) {
         $window.sessionStorage.setItem(key, cookie);
         delete $cookies[key];
    }
 });

The above code works for me however 'Resources' tab of Chrome inspection utility continues to show that the cookies are not deleted. I verified that the cookies are indeed deleted by printing them out:

console.log('START printing cookies AFTER deleting them');
 angular.forEach($cookies, function (cookie, key) {
    console.log(key + ': ' + $cookies[key] + '\n');
 });
 console.log('DONE printing cookies AFTER deleting them');

Hope this helps

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!