How to clear cookies in angular.js

后端 未结 3 1681
挽巷
挽巷 2021-01-07 18:21

Currently am using angulajs app.

I want to store some values in cookie. So i used angular-cookies-min script for add some values to cookies

I ha

3条回答
  •  难免孤独
    2021-01-07 18:54

    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

提交回复
热议问题