我在尝试清除我的angular应用程序中的cookies时,出现了错误 -“$ cookies.remove不是一个函数”。 据我所见,我按照angular文档和论坛上的建议进行操作以删除cookies。
下面是处理此操作的服务代码:
下面是处理此操作的服务代码:
app.service('authService', function ($cookies) {
this.SetUsername = function (username) {
$cookies.username = username;
}
this.GetUsername = function () {
return $cookies.username;
}
this.clearCookie = function(){
$cookies.remove("username");
}
});
get和set函数都能正常工作,只有在调用清除cookie函数时才会出现问题。
console.dir($cookies);
获取对象内容。是否定义了删除函数?你需要打开浏览器控制台(F12?)来查看输出。 - Peter Paul Kiefer