Then the previous article
Building a chat room client using Angularjs
<!doctype html>
Change node. js
Angular.module (' justchatting ', []) angular.module (' justchatting '). Factory (' socket ', function ($rootScope) {var Socket = Io.connect ('/') return {on:function (EventName, callback) {Socket.on (EventName, function () {var args = arguments $rootScope. $apply (function () {callback.apply (Soc Ket, Args)})}, Emit:function (EventName, data, callback) {socket. Emit (eventName, data, function () {var args = arguments $rootScope. $apply (function () { if (callback) {callback.apply (socket, args)}}) })}}) Angular.module (' justchatting '). Directive (' Ctrlenterbreakline ', function () {return function (scope, element, Attrs) {var Ctrldown = False Element.bind ("KeyDown", function (evt) {if (Evt.which = = = 17) { CtrlDown = True SetTimeout (function () {Ctrldown = false}, 1000) if (Evt.which = = =) {if (Ctrldown) {Element.val (Element.val () + ' \ n ') } else {scope. $apply (function () {scope. $eval (Attrs.ctrlenterbrea KLine); }); Evt.preventdefault ()}}); };}); Angular.module (' justchatting '). Controller (' Messagecreatorctrl ', function ($scope, socket) {$scope. CreateMessage = function () {socket.emit (' messages.create ', $scope. newmessage) $scope. Newmessage = '}}) Angular.module ( ' justchatting '). Directive (' Autoscrolltobottom ', function () {return {link:function (scope, element, Attrs) { Scope. $watch (function () {return Element.children (). length; }, function () { Element.animate ({scrollTop:element.prop (' scrollheight ')}, 100 0); } ); } };}); Angular.module (' justchatting '). Controller (' Roomctrl ', function ($scope, socket) {$scope. messages = [] Socket.on (' mes Sages.read ', function (messages) {$scope. Messages = messages}) Socket.on (' Messages.add ', function (message) {$scope. Messages.push (Message)}) Socket.emit (' Messages.read ')})
A humble chat room was finished.
Project Source code address:Https://github.com/edagarli/chattingnode
Socket.io+angular.js+express.js do a chat application (iv)