mirror of
https://github.com/taobataoma/meanTorrent.git
synced 2026-05-06 04:25:39 +02:00
New 0.4 version
This commit is contained in:
34
modules/chat/client/controllers/chat.client.controller.js
Normal file
34
modules/chat/client/controllers/chat.client.controller.js
Normal file
@@ -0,0 +1,34 @@
|
||||
'use strict';
|
||||
|
||||
// Create the 'chat' controller
|
||||
angular.module('chat').controller('ChatController', ['$scope', 'Socket',
|
||||
function($scope, Socket) {
|
||||
// Create a messages array
|
||||
$scope.messages = [];
|
||||
|
||||
// Add an event listener to the 'chatMessage' event
|
||||
Socket.on('chatMessage', function(message) {
|
||||
$scope.messages.unshift(message);
|
||||
});
|
||||
|
||||
// Create a controller method for sending messages
|
||||
$scope.sendMessage = function() {
|
||||
// Create a new message object
|
||||
var message = {
|
||||
text: this.messageText
|
||||
};
|
||||
|
||||
// Emit a 'chatMessage' message event
|
||||
Socket.emit('chatMessage', message);
|
||||
|
||||
// Clear the message text
|
||||
this.messageText = '';
|
||||
};
|
||||
|
||||
// Remove the event listener when the controller instance is destroyed
|
||||
$scope.$on('$destroy', function() {
|
||||
Socket.removeListener('chatMessage');
|
||||
});
|
||||
|
||||
}
|
||||
]);
|
||||
Reference in New Issue
Block a user