我试图使用angularjs2将viewmodel对象添加到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]。谁能帮我。我是角度2的新手
答案 0 :(得分:0)
我认为在角度2中不可能,你最好在cookie中设置单个值,根据该值可以生成结果。 Cookie用于设置小值,因此最好避免将viewmodel对象设置为cookie。尝试设置单个值。