Warning: file_get_contents(/data/phpspider/zhask/data//catemap/1/ms-access/4.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Javascript 角形网袋2_Javascript_Websocket_Angular - Fatal编程技术网

Javascript 角形网袋2

Javascript 角形网袋2,javascript,websocket,angular,Javascript,Websocket,Angular,我想将WebSocket客户端集成到我的angular2应用程序中 我第一次尝试使用sock.js来实现这一点 创建了一个SockJS对象,如下所示: export class Core { private sock: any; constructor (private router: Router) { this.sock = new SockJS(AppSettings.WEBSOCK_ENDPOINT); } } 我的问题是angular2无法识别SockJ

我想将WebSocket客户端集成到我的angular2应用程序中

我第一次尝试使用sock.js来实现这一点 创建了一个SockJS对象,如下所示:

export class Core {

  private sock: any;

  constructor (private router: Router) {

    this.sock = new SockJS(AppSettings.WEBSOCK_ENDPOINT);

  }

}
我的问题是angular2无法识别SockJS类型

然后,我尝试在项目中使用提供的打字定义,但无法真正确定在何处以及如何设置打字

或者,我尝试使用angular2 websocket npm包,但当我在应用程序中这样做时:

import {$WebSocket} from 'angular2-websocket/angular2-websocket'
var ws = new $WebSocket("url");
我的IDE(Jetbrains WebStorm)告诉我$WebSocket至少需要2个参数

由于目前关于angular2中WebSocket的信息非常少,我决定询问是否有人可以向我解释一种在angular2项目中设置WebSocket的好方法

我使用angular2+网页包,并在此样板文件上构建了我的项目,如您在

其他参数是可选的

constructor(private url:string, private protocols?:Array<string>, private config?: WebSocketConfig  ) {
构造函数(私有url:字符串,私有协议?:数组,私有配置?:WebSocketConfig){
您可能还喜欢它的工作套接字示例(使用socket.io)


我还可以为angular2中的WebSocket推荐此实现:

谢谢。我认为我的IDE在ES6功能方面存在一些问题,这就是显示错误的原因。