Richard Searle

home

Angular, SSE and modifying a list model

08 Apr 2012

The previous example used a very simple model, consisting of a single String. A more realistic implementation would add the strings to a list.
<body ng-app>
 <div ng:controller="Main">
 <ul>
 <li ng:repeat="item in items">
 
 </li>
 </ul>
 </div>

<script type='text/javascript'>//<![CDATA[


var source = new EventSource('/events');

function Main($scope) {
 $scope.items = [];

source.addEventListener('right', function(e) {
 $scope.$apply(function() {
 $scope.items.push(e.data);
 });
 },false);
 }
 //]]>

 </script>
 </body>