简体   繁体   中英

document.cookie is empty in angular 2 component - JavaScript

I'm working on an Angular 2 app which has some components including LoginComponent and CompanyComponent .

I use ng2-cookies npm package in order to manage cookies. I set some cookies in LoginComponent but can't get them in CompanyComponent !

LoginComponent :

alert(document.cookie) // has results

CompanyComponent :

alert(document.cookie) // no results

Found the problem, thanks to CBroe 's comment

the problem causes by different path s. so I set cookies like so :

Cookie.set(Cookies.names.username, data.username, 1, '/');

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM