我目前正在按照这篇教程进行学习,现在我需要在我的Angular5组件中实例化SockJS客户端。
以下是我所做的:
I exectuted the following commands to install the required libraries:
npm install stompjs npm install sockjs-client npm install jquery
I imported the libraries to my component like so:
import { Stomp } from 'stompjs'; import { SockJS } from 'sockjs-client'; import $ from 'jquery';
Finally I tried to instantiate 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); } }); }); }
我找不到任何关于这个问题的信息。ERROR Error: Uncaught (in promise): TypeError: sockjs_client_1.SockJS is not a constructor