如何删除 ngCookie (angular-cookies)
How to delete ngCookie (angular-cookies)
我在启动我的应用程序时创建了一个名为 'stateCookie' 的 cookie。当我改变状态时,我将变量添加到该 cookie 中。当我注销时,我希望这个 cookie 被完全销毁,或者清空。
On their docs it's just remove() 我已经这样做了,但 cookie 仍然存在。即:$cookies.remove('stateCookie');
注销并登录后:
>>> refreshCookie {"ticker":"SPY","term_id_1":5112166,"term_id_2":30111615,"term_id_3":13064871}
this.logout = () => AuthFactory.webservice_logout().then((res) => {
// $cookies.remove('stateCookie');
angular.forEach($cookies, function(value, key) {
$cookies.remove(key);
});
// console.log('$cookies', $cookies);
// $cookies.map((value, key) => {
// $cookies.remove(key);
// });
const refreshCookie = $cookies.get('stateCookie');
console.log('!!!refreshCookie', refreshCookie);
$state.go('login', {}).then(() => {
$state.reload();
});
});
黑客修复
回到 login
状态后,我可以通过调用 window.reload 来清除 cookie。
$state.go('login', {}).then(() => window.location.reload(true));
试试这个:
this.logout = () => AuthFactory.webservice_logout().then((res) => {
// $cookies.remove('stateCookie');
var cookies = $cookies.getAll();
console.log(cookies);
angular.forEach(cookies, function(value, key) {
$cookies.remove(key);
});
// console.log('$cookies', $cookies);
// $cookies.map((value, key) => {
// $cookies.remove(key);
// });
const refreshCookie = $cookies.get('stateCookie');
console.log('!!!refreshCookie', refreshCookie);
$state.go('login', {}).then(() => {
$state.reload();
});
});
我在启动我的应用程序时创建了一个名为 'stateCookie' 的 cookie。当我改变状态时,我将变量添加到该 cookie 中。当我注销时,我希望这个 cookie 被完全销毁,或者清空。
On their docs it's just remove() 我已经这样做了,但 cookie 仍然存在。即:$cookies.remove('stateCookie');
注销并登录后:
>>> refreshCookie {"ticker":"SPY","term_id_1":5112166,"term_id_2":30111615,"term_id_3":13064871}
this.logout = () => AuthFactory.webservice_logout().then((res) => {
// $cookies.remove('stateCookie');
angular.forEach($cookies, function(value, key) {
$cookies.remove(key);
});
// console.log('$cookies', $cookies);
// $cookies.map((value, key) => {
// $cookies.remove(key);
// });
const refreshCookie = $cookies.get('stateCookie');
console.log('!!!refreshCookie', refreshCookie);
$state.go('login', {}).then(() => {
$state.reload();
});
});
黑客修复
回到 login
状态后,我可以通过调用 window.reload 来清除 cookie。
$state.go('login', {}).then(() => window.location.reload(true));
试试这个:
this.logout = () => AuthFactory.webservice_logout().then((res) => {
// $cookies.remove('stateCookie');
var cookies = $cookies.getAll();
console.log(cookies);
angular.forEach(cookies, function(value, key) {
$cookies.remove(key);
});
// console.log('$cookies', $cookies);
// $cookies.map((value, key) => {
// $cookies.remove(key);
// });
const refreshCookie = $cookies.get('stateCookie');
console.log('!!!refreshCookie', refreshCookie);
$state.go('login', {}).then(() => {
$state.reload();
});
});