Cookie value undefined in angular 6+

Tags: , ,



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.

Answer

you just forgot to return the token

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


Source: stackoverflow