angular 2 种子中 socket.io 的错误

Errors for socket.io in angular 2 seed

无法将 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;
}

使用该代码时,我收到类似

的错误

似乎您的套接字 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"
  }
}
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
    ...
    }