-
Notifications
You must be signed in to change notification settings - Fork 3
/
Copy pathindex.html
35 lines (34 loc) · 977 Bytes
/
index.html
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
<html ng-app="foo"> <!-- The module name here is very important //-->
<head>
<title>Tiny Angular.js + SSE Example</title>
<script src="http://code.angularjs.org/1.0.7/angular.min.js"></script>
</head>
<body>
<div ng-controller="FooCtrl">
<ul>
<li ng-repeat="bar in foos">{{ bar.value }}</li>
</ul>
</div>
</body>
<script>
angular.module('foo', []).factory('sse', function($rootScope) {
var sse = new EventSource('/stream');
return {
addEventListener: function(eventName, callback) {
sse.addEventListener(eventName, function() {
var args = arguments;
$rootScope.$apply(function () {
callback.apply(sse, args);
});
});
}
};
});
function FooCtrl($scope, sse) {
$scope.foos = [];
sse.addEventListener('message', function (e) {
$scope.foos.push({value: e.data});
});
}
</script>
</html>