Skip to content
Advertisement

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.

Advertisement

Answer

you just forgot to return the token

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