首页 > 解决方案 > 角度 6+ 中未定义的 Cookie 值

问题描述

我正在使用角度和节点 js。我使用“CookieService”包

token.service.ts 类

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

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

试图在我的streams.component.ts中使用令牌服务,但我在“GetToken”中未定义这是我的Streams.component.ts

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

请帮我解决这个问题。

标签: javascriptnode.jsangular

解决方案


您只是忘记归还令牌

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

推荐阅读