2017-02-28 84 views
1

无法在angular2-seed应用中整合socket.io。 其实我的代码是角度2种子中的socket.io错误

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

当使用代码我收到了如下的错误enter image description here

+1

我想你忘了问这个问题。 – Jai

+0

角2种子中的socket.io错误。 其实我的代码在角2种子应用程序。 当使用该代码时,我收到了一个错误。 –

+0

这个问题? – Jai

回答

0
Socket.io-client not loaded properly 

下面尝试,它的工作 NPM安装@类型/ socket.io客户端--save 定义socket.io -client在工具/配置/ seed.config.ts

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增加对生产间ode

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 
    ... 
    } 
1

看来你的插座IO没有加载!

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

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

而且如果u产生的分型为它然后,

{ 
    "ambientDependencies": { 
    ... 
    "socket-io-client":"github:DefinitelyTyped/DefinitelyTyped/socket.io-client/socket.io-client.d.ts#7de6c3dd94feaeb21f20054b9f30d5dabc5efabd" 
    } 
} 
+0

上面的代码要添加到test-config.js中??? –

+0

你正在使用哪个种子文件? 你必须这样做 https://github.com/mgechev/angular-seed/wiki/Add-external-dependency –

+0

它没有奏效,像“**属性'addPackagesBundles'错误不存在键入'ProjectConfig'**“ –