【问题标题】:angular-socket-io io is not definedangular-socket-io io 未定义
【发布时间】:2016-01-29 10:16:54
【问题描述】:

这里有一个建议:https://github.com/btford/angular-socket-io/issues/127

  • 确保你有 socket.io 客户端库:

    bower install socket.io-client --save
    

这并没有解决我遇到同样错误的问题。

  • 包含在 index.html 中:

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

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

    .factory('seatStatusSocket',function(socketFactory){ 
       var myIoSocket = io.connect(porturl); // io is not defined here, suddenly.
    
  • 它以前可以使用 lib 的远程副本。当这个错误开始时,我更改了 index.html 以链接本地副本,因为这个远程版本也收到了 Bad Gateway 错误(现在很好,但仍然没有像上面那样定义套接字 io)。

已删除:

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

【问题讨论】:

    标签: angularjs node.js socket.io ionic-framework bower


    【解决方案1】:

    你必须包含在 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
    

    【讨论】:

    • 谢谢!就是这样!我以为我有两个相同的,所以当第一个 socket.io-client 出现 Bad Gateway 错误时,我删除了它。当我更改为不同的工作 url 版本时,它起作用了。
    • 亲爱的读者:这是我的解决方案。希望能帮助到你。 github.com/angular-fullstack/generator-angular-fullstack/issues/…
    猜你喜欢
    • 2014-09-14
    • 1970-01-01
    • 2013-07-22
    • 2019-02-07
    • 2020-12-22
    • 1970-01-01
    • 1970-01-01
    • 2022-01-22
    • 1970-01-01
    相关资源
    最近更新 更多