【问题标题】:throws ERROR TypeError: Cannot read property 'emit' of undefined, has deprecated this is happening in my chat socket applicationthrows ERROR TypeError: Cannot read property 'emit' of undefined, has deprecated this is occur in my chat socket application
【发布时间】:2022-01-13 04:54:40
【问题描述】:

这是我收到错误的服务文件代码

 public sendMessage(msg: SocketMessage) {
this.socket.emit('check-message', msg);

}

checkNewMessages(): Observable<SocketMessage> {
    return Observable.create((observer) => {
      if (environment.production)
        this.socket.on('check-message', (message) => {
          observer.next(message);
        });

    })
  }

【问题讨论】:

标签: angular sockets


【解决方案1】:

您的套接字属性未定义。怎么申报?

也许你必须在你的服务构造函数中声明。

【讨论】:

  • 您的答案可以通过额外的支持信息得到改进。请edit 添加更多详细信息,例如引用或文档,以便其他人可以确认您的答案是正确的。你可以找到更多关于如何写好答案的信息in the help center
  • 如何将 socker.io 设置为本地环境??
猜你喜欢
  • 2017-12-29
  • 1970-01-01
  • 2021-09-18
  • 2023-01-19
  • 2019-02-12
  • 1970-01-01
  • 2021-09-20
  • 2021-06-08
  • 1970-01-01
相关资源
最近更新 更多