角度-Socket.IO io未定义

7
这里有一个建议: https://github.com/btford/angular-socket-io/issues/127
  • make sure you have socket.io client library:

    bower install socket.io-client --save
    
这并没有解决我的问题,仍然出现了同样的错误。
  • including in index.html:

    script src="lib/angular-socket-io/socket.js"
    
  • in app.js

    angular.module('starter', ['ionic', 'starter.controllers', 'starter.services',       
     'starter.directives', 'btford.socket-io'])
    
  • in services.js

    .factory('seatStatusSocket',function(socketFactory){ 
       var myIoSocket = io.connect(porturl); // io is not defined here, suddenly.
    
  • It was working before, using a remote copy of the lib. When this error started, I changed index.html to link a local copy, as this remote version also received a Bad Gateway error (now fine, but still socket io is not defined as above).

被移除:
script src="http://chat.socket.io/socket.io/socket.io.js"

版本
socket.io@1.3.7 node_modules/socket.io
node --version
v0.12.7
1个回答

10

你需要在index.html中包含:

script src="<bowerComponentPath>/socket.io-client/socket.io.js"

在此之前:

script src="<bowerComponentPath>/angular-socket-io/socket.js"

还有一点,这是必需的:

bower install socket.io-client --save

2
谢谢!就是这样!我以为我有两个相同的,所以当第一个socket.io-client出现Bad Gateway错误时,我将其删除了。当我更改为另一个可用的url版本后,它就可以工作了。 - mylord
1
亲爱的读者:这是我的解决方案。希望能对您有所帮助。https://github.com/angular-fullstack/generator-angular-fullstack/issues/766 - Alejandro Teixeira Muñoz

网页内容由stack overflow 提供, 点击上面的
可以查看英文原文,
原文链接