我阅读了很多文章,但仍然无法使 cookie 工作。我有一个用于登录页面的控制器,这个控制器基本上调用了登录服务。在服务回调函数中,我设置了 cookie:
$cookieStore.uid = response.ui;
$cookieStore.email = response.email;
$cookieStore.auth = response.cookie;
$location.path('/');
之后,我在我的索引视图上进行重定向。在索引视图的控制器中,我尝试在 cookie chacker 服务中检查 cookie。
var email = $cookieStore.email;
var auth = $cookieStore.auth;
if (typeof email !== 'undefined' && typeof auth !== 'undefined') {
success("");
}
这仅适用于我从登录重定向到页面的那一刻。当我移动到不同的视图或重新加载页面时,我的 cookie 丢失了。