【发布时间】:2017-08-16 22:37:47
【问题描述】:
我正在尝试使用 angularjs2 将视图模型对象添加到 cookie 中。我已经尝试了很多,但还没有工作。我
private setCookie(name: string, value: any, expireDays: number, path: string = "") {
let d: Date = new Date();
d.setTime(d.getTime() + expireDays * 24 * 60 * 60 * 1000);
let expires: string = "expires=" + d.toUTCString();
document.cookie = name +`enter code here` "=" + value + "; " + expires + (path.length > 0 ? "; path=" + path : "");
}
我试过这样,
this.setCookie("CookieConstant", ViewModel, 1);
当我在浏览器中检查 cookie 值时,我只能看到 [Object Object]。谁能帮我。我是 Angular 2 的新手
【问题讨论】:
-
您希望看到什么?如果
ViewModel是一个对象,那么cookie 将包含文本[object Object],以及其他"CookieConstant",因为当您将object附加到string时,该对象将转换为string它可能是这样附加的。
标签: angularjs node.js asp.net-mvc angular npm