Javascript &引用;TypeError:无法读取属性';应用';“未定义”的定义;
使用node、express、socket.io、jade和angular。获取错误:Javascript &引用;TypeError:无法读取属性';应用';“未定义”的定义;,javascript,angularjs,node.js,express,Javascript,Angularjs,Node.js,Express,使用node、express、socket.io、jade和angular。获取错误:TypeError:无法读取未定义的属性“apply”。有什么建议吗 index.js: module.exports = function(app, res) { res.render('index', { title: 'Express' }); var io = app.get('io'); io.on('connection', function(socket){ }); }; ind
TypeError:无法读取未定义的属性“apply”
。有什么建议吗
index.js:
module.exports = function(app, res) {
res.render('index', { title: 'Express' });
var io = app.get('io');
io.on('connection', function(socket){
});
};
index.jade:
extends layout
block content
script.
var app = angular.module('hackigur', []);
var socket = io.connect();
var refreshTimer = 10;
app.controller('UpdateController', function($scope){
//socket.on('update', function(msg){
//$scope.refreshTimer = msg;
//$scope.$apply();
//});
setInterval(secondTick,1000);
function secondTick() {
if(refreshTimer != 0) {
refreshTimer -= 1;
}
$scope.refreshTimer = refreshTimer;
$scope.$apply();
};
});
h1= title
p Welcome to #{title}
div(ng-controller="UpdateController")
p(ng-bind="refreshTimer")
layout.jade:
doctype html
html(ng-app="hackigur")
head
title= title
script(src = "/socket.io/socket.io.js")
script(src = "/js/angular/angular.min.js")
body
block content
doctype html
html(ng app=“hackigur”)
头
头衔
脚本(src=“/socket.io/socket.io.js”)
脚本(src=“/js/angular/angular.min.js”)
身体
块内容
完全错误:
Server listening on port 3000
TypeError: Cannot read property 'apply' of undefined
at Server.(anonymous function) [as on] (D:\Projects\hackigur\node_modules\so
cket.io\lib\index.js:364:15)
at module.exports (D:\Projects\hackigur\server\api\index.js:30:8) at ...
服务器侦听端口3000
TypeError:无法读取未定义的属性“apply”
在服务器上。(匿名函数)[as on](D:\Projects\hackigur\node\u modules\so
cket.io\lib\index.js:364:15)
在module.exports(D:\Projects\hackigur\server\api\index.js:30:8)处。。。
我的
路由器
调用了我的index.js
在模块中通过app
。导出
,如下所示:
module.export = function (app) {
app.get( ... , function(..., res) {
require(index.js)(app)(res);
};
我需要为模块外部的应用程序
声明一个变量。导出
:
var x;
module.export = function (app) {
x = app;
app.get( ... , function(..., res) {
require(index.js)(x)(res);
};
我不完全理解它为什么会工作,但它似乎通过应用上述方法将正确的
app
对象传递给app.get
。FYI index.js:30是行:io.on('connection',function(socket)){…这段代码昨晚确实有效,我今晚又试了一次,结果它死掉了。你能把index.js的全部内容都发布出来吗?似乎在你没有包含在这个问题中的行上发生了错误。我只是想到你有多个index.js(我的错)。你能至少澄清一下你提供了哪个index.js吗?只有一个index.js…另一个是index.jade。我已经发布了上面几乎所有的index.js;剩下的只是一个大函数,我已经完全对outindex.js进行了注释。我发布的是server/api/index.js;另一个socket.io我没有碰过,不管npm怎么说在socket.io的节点_模块中调用