精华 《使用angular和socket.io搭建聊天室》,求大家拍砖!
发布于 10 年前 作者 island205 14002 次浏览 最后一次编辑是 8 年前

最近在写使用angular和socket.io搭建聊天室,希望坛子里的童鞋可以去读读,提提意见!

36 回复

求拍砖

大家就不能拍砖么?

给一个demo的地址呀~直接看demo~~~

厉害,收藏了

访问http://localhost:3000完,弹出一个东西,然后就挂了。

module.js:340 throw err; ^ Error: Cannot find module './socket’ at Function.Module._resolveFilename (module.js:338:15) at Function.Module._load (module.js:280:25) at Module.require (module.js:364:17) at require (module.js:380:17) at SocketNamespace.<anonymous> (/home/www/nodejs/TechNode/app.js:14:3) at SocketNamespace.EventEmitter.emit [as $emit] (events.js:117:20) at connect (/home/www/nodejs/TechNode/node_modules/socket.io/lib/namespace.js:292:10) at /home/www/nodejs/TechNode/node_modules/socket.io/lib/namespace.js:308:13 at SocketNamespace.authorize (/home/www/nodejs/TechNode/node_modules/socket.io/lib/namespace.js:252:5) at SocketNamespace.handlePacket (/home/www/nodejs/TechNode/node_modules/socket.io/lib/namespace.js:302:14)

围观一下,随便看了LZ的GitHub上有很多前端资源啊,像Seajs我们这边前端都有用,因主要搞backend还没仔细去看,收藏了先!

寸志你都对外了?支持下~

angularjs1.2.5版似乎没有$routeProvider了?怎么破?

没道理呀,最好使用https://github.com/island205/TechNode/tree/master/how-to-build-chat-app-with-socket.io-and-angular/examples/chapter03/TechNode 这里的代码,试试

先让大家看看,怕写得不好

请升级angular

@island205 貌似是route模块需要引入angular-route.js,不然找不到。还以为官方去掉了这功能。

    • 尼玛,我又遇到问题。用了bower之后,请求的css和js的content-type都变成text/html,我已经无语了。这是服务器问题还是…

谢谢你的例子,写的很好。 发现有点小问题: 01-最简单的聊天室 上说要在.bowerrc文件中添加:

{
  "directory" : "webapp/components"
}

但是在实际的代码中写的是:

{
  "directory" : "static/components"
}

这个和bower应该没有关系,应该是资源没有请求到,你看看是不是和楼下遇到了同样的问题?

抱歉,文字和代码没有对应上!看来我还要细心的校审即便,非常感谢!

第一篇里指令绑定不上,不知道哪里出错了 html: <div class=“panel-body room-content”> <div class=“messages” auto-scroll-to-bottom> <div class=“list-group” ng-repeat=“message in messages”> 某某:{{message}} </div> </div> <form class=“message-creator” ng-controller=“MessageCreatorCtrl”> <div class=“form-group”> <textarea required class=“form-control message-input” ng-model=“newMessage” ctrl-enter-break-line=“createMessage()” placeholder=“Ctrl+Enter to quick send”></textarea> </div> </form> </div>

js: //directive angular.module(‘techNodeApp’).directive(‘ctrl-enter-break-line’,function(){ console.log(‘directive %s’,ctrlEnterBreakLine); return function(scope,element,attrs){ var ctrlDown = false; console.log(“keydown event: %s”,evt.which); element.bind(‘keydown’,function(evt){ if(evt.which === 17){//ctrl key ctrlDown=true; setTimeout(function(){ ctrlDown = false; },1000); } if(evt.which === 13){//enter key if(ctrlDown){ element.val(element.val()+’\n’); }else{ scope.$apply(function(){ scope.$eval(attrs.ctrlEnterBreakLine); }); evt.preventDefault(); } } }); }; });

//directive angular.module(‘techNodeApp’).directive(‘auto-scroll-to-bottom’,function(){ console.log(‘autoScrollToBottom’); return { link:function(scope,element,attrs){ scope.$watch( function(){ return element.children().length; }, function(){ element.animate({ scrollTop:element.prop(‘scrollHeight’) },1000); }

      );
    }
};

});

angular.module(‘techNodeApp’).directive(‘ctrlEnterBreakLine’, function() {}) 应该是这个ctrlEnterBreakLine

@island205 对的是我的代码里指令名称绑定的不对 不多example中的指令函数的参数有点问题,不知道是不是来网页中显示有问题

angular.module(‘techNodeApp’).directive(‘ctrlEnterBreakLine’, function() { return function(scope, element, attrs)

scope, element, attrs 这三个参数需要加‘$'符的

学 angularjs的各位同学 给大家推荐一个blog,写得很详细 http://zouyesheng.com/angular.html#toc34

socket.io 没有 websocket 通用

@mq1980 这个指令绑定不上,最后怎么解决的呢?我先在也遇到这个问题了。index.html里面的ctrlEnterBreakLine, autoScrollToBottom和directive里面的指令是一致的,但是就是无法绑定。请指教,谢谢。。。

@island205 这个指令绑定不上,最后怎么解决的呢?我先在也遇到这个问题了。index.html里面的ctrlEnterBreakLine, autoScrollToBottom和directive里面的指令是一致的,但是就是无法绑定。请指教,谢谢。。。

@mq1980 你好,你是怎么弄的呢???

怎么我打开链接是 404页面。

寸老师 求更新地址

什么更新地址?

怎么变精华了?

@island205 应该是被挖坟了,上面那个地址404了,应该这里吧:https://github.com/island205/technode-tutorial

@island205 hi,我想知道一下,在technode最简单的聊天室那节,我的代码和你的一样,为什么按下CTRL+ENTER之后, 数据不能到RoomCtrl里面去呢?其他的都没有问题,就是无法发送消息出去。您猜想大概是什么情况呢?请指导一下,谢谢了。。。

@island205 这个我有,不知道为什么就是不行。。。

回到顶部