I'm trying to write an angularJS service for long polling in my application, using $http.
Here's my 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
    };
});
The basic idea would be to inject this service whenever I need polling on a $http call. I'm using it inside a controller :
app.controller('myCtrl', function($scope, $http, Poller){
    $scope.polledVar = Poller.poll($http.get('api/getVar'), 1000);
});
When using this code I get the following error :
TypeError: Cannot call method 'then' of undefined
 
     
     
    