AngularJS – Polling for data

Polling for data in AngularJS can be accomplished quickly using the $timeout function. You pass two parameters to the $timeout instance; The first being the method to call, the second being the delay (in milliseconds).

$timeout($scope.getSomeData, 200);

Combining this with the counter enables you to quickly wire-up a repeated call for data over a specified timeframe.

$scope.keepPolling = function () {
    if ($scope.isPolling) {
        if ($scope.pollCount > 0) {
            $timeout($scope.getSomeData, 200);
        } else {

A full example can be seen in the following Gist