【问题标题】:Errors for socket.io in angular 2 seed角度 2 种子中的 socket.io 错误
【发布时间】:2017-02-28 06:15:13
【问题描述】:

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

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

【问题讨论】:

  • 我猜你忘了问这个问题。
  • 角度 2 种子中的 socket.io 错误。实际上我在 Angular 2 种子应用程序中的代码。使用该代码时,我收到类似的错误。
  • 这是个问题吗?
  • 当我使用上述代码时,即在我的 Angular 种子应用程序中使用 socket.io 时,我遇到了这些错误。
  • 在 system.config.json 中添加正确的 socket.io-parser.js 文件路径..

标签: angular socket.io angular2-seed


【解决方案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"
  }
}

【讨论】:

【解决方案2】:
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
    ...
    }

【讨论】:

    猜你喜欢
    • 2016-03-22
    • 2023-03-29
    • 2023-03-04
    • 2016-05-26
    • 2015-01-19
    • 2016-08-19
    • 2016-11-20
    • 2016-06-18
    • 2018-12-31
    相关资源
    最近更新 更多