【发布时间】:2018-03-15 16:06:12
【问题描述】:
我现在正在关注这个tutorial,我已经到了关键点,我必须在我的 Angular5 组件中实例化我的 SockJS-Client。
这是我所做的:
-
我执行了以下命令来安装所需的库:
npm install stompjs npm install sockjs-client npm install jquery -
我像这样将库导入到我的组件中:
import { Stomp } from 'stompjs'; import { SockJS } from 'sockjs-client'; import $ from 'jquery'; -
最后我尝试实例化 SockJS:
constructor(){ this.initializeWebSocketConnection(); } initializeWebSocketConnection(){ let ws = new SockJS(this.serverUrl); //<- This is the line causing the error this.stompClient = Stomp.over(ws); let that = this; this.stompClient.connect({}, function(frame) { that.stompClient.subscribe("/chat", (message) => { if(message.body) { $(".chat").append("<div class='message'>"+message.body+"</div>") console.log(message.body); } }); }); }
我得到的错误是:
错误错误:未捕获(承诺中):TypeError:sockjs_client_1.SockJS 不是构造函数
我找不到关于这个问题的任何信息。
【问题讨论】:
标签: angular typescript websocket angular5 sockjs