1

无法将 socket.io 集成到 angular2-seed 应用程序中。其实我的代码是

private mySocket:any;    
getSocketValue() {
    console.log("this.mySocket"+this.mySocket)
    if(this.mySocket) {
      this.mySocket = io(Config.socket_url);
    }
    return this.mySocket;
}

使用该代码时,我收到一个错误,例如在此处输入图像描述

4

2 回答 2

1

似乎您的套接字 io 未加载。!

将它包含在您的 systemJS 配置中。

System.config({
    packages: {
        ...
        "socket.io-client": {"defaultExtension": "js"}
    },
    map: {
        "socket.io-client": "node_modules/socket.io-client/socket.io.js"
    }
});

如果你为它生成了类型,那么,

{
  "ambientDependencies": {
    ...
    "socket-io-client":"github:DefinitelyTyped/DefinitelyTyped/socket.io-client/socket.io-client.d.ts#7de6c3dd94feaeb21f20054b9f30d5dabc5efabd"
  }
}
于 2017-02-28T06:23:22.430 回答
0
Socket.io-client not loaded properly

在下面尝试,它工作 npm install @types/socket.io-client --save 在 tools/config/seed.config.ts 中定义 socket.io-client

i.e in SYSTEM_CONFIG_DEV->
path: {
...,
'socket.io-client' : `node_modules/socket.io-client/dist/socket.io`,// for latest versions of socket.io
'socket.io-client' : `node_modules/socket.io-client/socket.io`,// for older versions of socket.io
...
}

为生产模式添加 SYSTEM_BUILDER_CONFIG

path: {
    ...,
    'socket.io-client' : `node_modules/socket.io-client/dist/socket.io`,// for latest versions of socket.io
    'socket.io-client' : `node_modules/socket.io-client/socket.io`,// for older versions of socket.io
    ...
    }
于 2017-03-01T07:50:41.167 回答