2016-11-07 94 views
0

我在我的项目中使用了angularjs1.5.5。关闭浏览器后,为什么不保存cookie?

我使用$饼干服务在我project.I创建并存储在cookie中的一些凭证:

this.setCookie = function (inspectorName) { 
    $cookies.put('inspectorName', inspectorName, { 
     expires: new Date(new Date() + 1, new Date().getMonth(), new Date().getDate()) 
    }); 
} 

在这里,我如何访问饼干:

var credentials = $cookies.get('inspectorName'); 

但是当我关闭和打开页面,我尝试按行获得上面的cookie,我得到'未定义'。

任何想法为什么cookie在关闭浏览器后没有保存?

+0

expires value is null as null。因此其取消到期时间作为浏览器会话。意味着cookie的生命将在浏览器关闭时过期 –

回答

3
new Date(new Date() + 1, new Date().getMonth(), new Date().getDate()) 

到期值将会作为null.So其采取的到期时间为cookie的浏览器上会接近到期的浏览器session.Means生活。新增有效将来的日期,我相信它会工作。

相关问题