我想將WebSocket客戶端集成到我的angular2應用程序中。angular2中的WebSockets
我弗里斯特試圖做到這一點使用sock.js https://github.com/sockjs/sockjs-client 創造了SockJS對象是這樣的:
export class Core {
private sock: any;
constructor (private router: Router) {
this.sock = new SockJS(AppSettings.WEBSOCK_ENDPOINT);
}
}
我的問題是angular2是無法識別SockJS類型。
然後,我嘗試使用https://github.com/retyped/sockjs-client-tsd-ambient/blob/master/sockjs-client.d.ts在我的項目中提供的打字定義,但無法弄清楚在哪裏以及如何設置打字。
或者我試圖用angular2-WebSocket的NPM包https://github.com/afrad/angular2-websocket,但是當我這樣做在我的應用程序:
import {$WebSocket} from 'angular2-websocket/angular2-websocket'
var ws = new $WebSocket("url");
我的IDE(Jetbrains的WebStorm)告訴我,$的WebSocket預計至少2個參數。
由於目前我很少有關於angular2中的WebSockets的信息,因此我決定詢問是否有人能夠向我解釋一個在angular2項目中設置WebSocket的好方法。
我用angular2 +的WebPack和建立在這個樣板https://github.com/angular/angular2-seed
感謝我覺得我的IDE與ES6功能的一些問題,這就是爲什麼被證明錯誤。 –
auctionApp確實是一個很好的例子 – Ted