我正在为我的 angular5 应用程序使用 ngx-cookie-service
。谁能帮我看看如何设置过期日期?
我尝试这样:
setCookies($event){
this.cookieService.set( 'retailAppCookies', "true", 30 );
this.cookieService.set( 'expires', '2030-07-19' );
}
但不起作用。有人帮帮我吗?
最佳答案
2021年,您可以添加日期,但它是日期实例。以下示例设置 cookie 有效期为 1 小时
cookieService.set('test', 'Hello World', { expires: new Date(new Date().getTime() + 1000 * 60 * 60); });
查看 API documentation了解更多详细信息。
关于angular - 如何使用 `ngx-cookie-service` 设置 cookie 过期日期,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/50832428/