【问题标题】:signalR: Connection ID returns undefined from angular 5 clientsignalR:连接 ID 从 Angular 5 客户端返回未定义
【发布时间】:2018-04-21 07:33:27
【问题描述】:

我正在尝试在 .done 范围内开始连接到 signlar 服务器(使用 start())后获取我的连接 ID 值。但不幸的是,我一直没有为它定义。 希望各位大神帮忙看看是什么问题。 谢谢!

  public startConnection(): void
  {
      this.connection = $.hubConnection('http://localhost:62752');
      this.proxy = this.connection.createHubProxy('ChatHub');
      this.proxy.on('messageReceived', (a,b,c,d,e,f) => 
          this.onMessageReceived(a,b,c,d,e,f));

      this.connection.start().done((data: any) => {
          console.log('Connected to Chat Hub');
          this.connectionID = $.connection.hub.id;
          console.log($.connection.hub.id);//undefined
          this.registerConnection();         
      });
  }

【问题讨论】:

    标签: javascript angular typescript signalr signalr-hub


    【解决方案1】:

    花了更多时间解决问题后,我能够解决它! 我发现 ID 在 data["id"] 下可用。

    • “data”是我给 done 函数的参数起的名字。

    希望以后能帮助更多的人,因为我真的 在谷歌上找不到答案。

    【讨论】:

    • 您能详细说明一下吗?我在您的原始问题中没有看到“数据”,所以不明白这有什么关系。
    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2015-01-31
    相关资源
    最近更新 更多