title: Realtime Updates in AngularJS
body: <p>In an attempt to learn Angular &amp; Codeigniter I have expanded the initial new tutorial (from CI). In it's current stage, it automatically displays new posts &amp; removes deleted posts from the page &amp; of course updates model/DB. -- <strong>I assume I'm not doing this the most effective way for AngularJS though. Feedback on my code would be helpful for that.</strong> --</p>
  
  <p>However, my main concern is <strong><em>how to do differential updates in Angular?</em></strong>
  When I accomplished this via jQuery, I simply appended a timestamp to my ajax url. Then I would grab that time in the controller &amp; assign it to a variable &amp; do a comparison to pull any additional posts. It worked great. It would only pull new stories (if they exist), if they didn't exist then there wouldn't be much overhead.</p>
  
  <p>However, currently in Angular, it's pulling the entire JSON data with every request (every 5 seconds) - for large scale apps, this will consume excessive bandwidth. How can I differentiate that and only pull new posts?</p>
  
  <p><strong>controllers.js (angular controller)</strong></p>
  
  <pre><code>var timestamp = '';
  function NewsListCtrl($scope, $http, $timeout) { 
  
  $scope.newsRequest = function(){
      $http.get('/ci/index.php/news/get_news_ajax/' + timestamp).success(function(data) {
          timestamp = $.now();
          $scope.news = data;
      });
  };
  $scope.newsRequest();
  setInterval(function(){
      $scope.$apply(function(){
             $scope.newsRequest();
      });
  }, 5000);
  
  }
  </code></pre>
  
  <p>The above code successfully passes the time into the 3rd Segment of the URL (3rd according to Codeigniter). When the page initially loads, all posts appear. Then after newsRequest() fires again, I get a blank page. I assume because there aren't any newer posts, it assigns the empty array to my $scope.news. <strong>How would I fix this so that the newer posts are appended?</strong></p>
  
  <p>(And like I said, I assume I'm not taking advantage of AngularJS ng-repeat to the fullest. If someone has a better solution, please enlighten me!)</p>