简体   繁体   中英

Cookie value undefined in angular 6+

i am using angular and node js. i use "CookieService" package

token.service.ts class

 SetToken(token) {
    this.cookieService.set('chat_token', token);
  }

  GetToken() {
     this.cookieService.get('chat_token');
  }

trying to use token service in my streams.component.ts but i got undefined in "GetToken" here is my Streams.component.ts

ngOnInit() {
    this.token = this.tokenService.GetToken();
    console.log(this.token);
  }

please help me out to solve this.

you just forgot to return the token

  GetToken(): string {
     return this.cookieService.get('chat_token');
  }

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