Richard Searle's Blog

Thoughts about software

Angular, SSE and modifying a list model

Posted by eggsearle on April 8, 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">
 {{item}}
 </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>
Advertisements

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s

 
%d bloggers like this: