无法在angular2-seed应用中集成socket.io。 其实我的代码是
private mySocket:any;
getSocketValue() {
console.log("this.mySocket"+this.mySocket)
if(this.mySocket) {
this.mySocket = io(Config.socket_url);
}
return this.mySocket;
}
的错误消息
答案 0 :(得分:1)
好像你的socket 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"
}
}
答案 1 :(得分: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
...
}