title: Writing an angularJS poller
body: <p>I'm trying to write an angularJS service for long polling in my application, using $http.</p>
  
  <p>Here's my code :</p>
  
  <pre><code>app.factory('Poller', function($http, $timeout){
      var poll = function(http, tick){
          http.then(function(r){
              $timeout(poll, tick);
              return r.data;
          });
      };
  
      return{
          poll: poll
      };
  });
  </code></pre>
  
  <p>The basic idea would be to inject this service whenever I need polling on a $http call. I'm using it inside a controller :</p>
  
  <pre><code>app.controller('myCtrl', function($scope, $http, Poller){
      $scope.polledVar = Poller.poll($http.get('api/getVar'), 1000);
  });
  </code></pre>
  
  <p>When using this code I get the following error :</p>
  
  <pre><code>TypeError: Cannot call method 'then' of undefined
  </code></pre>