angularjs - Angular 套接字 io 未定义

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

这里有一个建议: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

最佳答案

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

关于angularjs - Angular 套接字 io 未定义,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/33411413/

相关文章:

javascript - Angular TypeError : text. 替换不是函数。重复

angularjs - 如何使 textangulars 插入 html 允许使用 iframe

javascript - AngularJS:在模型和 View 之间异步收集附加数据

javascript - 搞清楚 Node.js + Redis + Express.js 和可爱的异步回调

node.js - 使用代理的客户端的socket.io flash(和其他)回退的正确设置

javascript - 如何使用 Node js 和 socket.io 在 mysql 数据库中插入新记录时通知并更新客户端

javascript - For 循环以错误的顺序返回 Promise

node.js - Node/Express 文件上传

node.js - Node 冲突 : Nodejs -v works, 但不是 Node -v

node.js - 如何获取套接字的主机名?