-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathapp.js
39 lines (28 loc) · 850 Bytes
/
app.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
var twittsApp = angular.module('twittsApp', []);
twittsApp.controller('TwittsController', function ($scope) {
$scope.hashtag = "";
$scope.socket;
$scope.twitts = [];
$scope.receiveTwitt = function(data) {
$scope.twitts.unshift(data);
$scope.$apply();
}
$scope.serverDisconnected = function() {
console.log("Server disconnected");
}
$scope.hashtagOnKeyUp = function(event) {
if(event.keyCode == 13) {
$scope.setHashtag($scope.hashtag);
$scope.twitts = [];
}
}
$scope.setHashtag = function(hashtag) {
$scope.socket.emit('search_hashtag', hashtag);
}
$scope.connect = function() {
$scope.socket = io.connect('http://localhost:8000');
$scope.socket.on('new_twitt', this.receiveTwitt);
$scope.socket.on('disconnect', this.serverDisconnected);
}
$scope.connect();
});