How to remove all cookies in Angularjs? -
I can set a cookie like this:
$ cookiestore.put (' Mycookie ',' I'm a cookie ');
and I can remove it from
$ cookieStore.remove ('mycookie');
But how can I remove all cookies?
OK, obviously this can not be the best solution, but I got a workaround Is:
Angular. ForEach ($ cookies, function (v, k) {$ cookiestore.remove (k);});
But I still appreciate if there is a better solution. I'm really curious about why not an underlying $ cookiestore.removeAll ()
method ... < / P>
ngCookies module is not required to install.
Editing
With version 1.4, the $ cookiestore
has been deprecated. Instead, you can use the $ Cookies
service to get all cookies with the $ cookies.getAll ()
and each with the $ cookies.remove (' Key ').
var cookies = $ Cookies.getAll (); Angular For each (cookies, functions (v, k) {$ cookies.remove (k);});
Comments
Post a Comment