Poller service for AngularJS applications
5 people use it
Author: 4766435?v=2 emmaguo

Angular Poller

Build Status devDependency Status

Lightweight AngularJS poller service which can be easily injected into controllers. It uses a timer and sends requests every few seconds to keep the client synced with the server. If you need the data to be exact real-time such as in a chat box, you should use long polling or WebSocket instead.

Demo site:


Install with bower:

Add a <script> to your index.html:

Basic Usage

Advanced Usage


Error Handling

One way to capture error responses is to use the catchError option. It indicates whether poller should get notified of error responses. ```javascript var myPoller = poller.get(myResource, { catchError: true });

myPoller.promise.then(null, null, function (result) {

}); ```

Alternatively you can use AngularJS interceptors for global error handling like so: javascript angular.module('myApp', ['emguo.poller']) .config(function ($httpProvider) { $httpProvider.interceptors.push(function ($q, poller) { return { 'responseError': function (rejection) { if (rejection.status === 503) { // Stop poller or provide visual feedback to the user etc poller.stopAll(); } return $q.reject(rejection); } }; }); });

Multiple Resources

Multiple Controllers

In order to automatically stop all pollers on navigating between views with multiple controllers, you can use pollerConfig. ```javascript var myModule = angular.module('myApp', ['emguo.poller']);

myModule.config(function (pollerConfig) { pollerConfig.stopOnStateChange = true; // If you use $stateProvider from ui-router. pollerConfig.stopOnRouteChange = true; // If you use $routeProvider from ngRoute. }); ```

comments powered by Disqus
This page was last updated about 4 years ago.