@@ -66,15 +66,12 @@ angular.module('myApp', ['emguo.poller']);
66
66
67
67
You can also use [ cdnjs] ( https://cdnjs.com/libraries/angular-poller ) files:
68
68
``` html
69
- <script src =" http://cdnjs.cloudflare.com/ajax/libs/angular-poller/0.4.4 /angular-poller.js" ></script >
70
- <script src =" http://cdnjs.cloudflare.com/ajax/libs/angular-poller/0.4.4 /angular-poller.min.js" ></script >
69
+ <script src =" http://cdnjs.cloudflare.com/ajax/libs/angular-poller/0.4.5 /angular-poller.js" ></script >
70
+ <script src =" http://cdnjs.cloudflare.com/ajax/libs/angular-poller/0.4.5 /angular-poller.min.js" ></script >
71
71
```
72
72
73
73
## Quick configuration
74
74
``` javascript
75
- // Inject angular poller service.
76
- var myModule = angular .module (' myApp' , [' emguo.poller' ]);
77
-
78
75
myModule .controller (' myController' , function ($scope , $resource , poller ) {
79
76
80
77
// Define your resource object.
@@ -103,9 +100,6 @@ myModule.controller('myController', function($scope, $resource, poller) {
103
100
104
101
### Customize $resource poller
105
102
``` javascript
106
- // Inject angular poller service.
107
- var myModule = angular .module (' myApp' , [' emguo.poller' ]);
108
-
109
103
myModule .controller (' myController' , function ($scope , $resource , poller ) {
110
104
111
105
// Define your resource object.
@@ -241,29 +235,25 @@ myPoller.promise.then(null, null, function(result) {
241
235
242
236
Alternatively you can use AngularJS ` interceptors ` for global error handling like so:
243
237
``` javascript
244
- angular .module (' myApp' , [' emguo.poller' ])
245
- .config (function ($httpProvider ) {
246
- $httpProvider .interceptors .push (function ($q , poller ) {
247
- return {
248
- ' responseError ' : function (rejection ) {
249
- if (rejection .status === 503 ) {
250
- // Stop poller or provide visual feedback to the user etc
251
- poller .stopAll ();
252
- }
253
- return $q .reject (rejection);
238
+ myModule .config (function ($httpProvider ) {
239
+ $httpProvider .interceptors .push (function ($q , poller ) {
240
+ return {
241
+ ' responseError ' : function (rejection ) {
242
+ if (rejection .status === 503 ) {
243
+ // Stop poller or provide visual feedback to the user etc
244
+ poller .stopAll ();
254
245
}
255
- };
256
- });
246
+ return $q .reject (rejection);
247
+ }
248
+ };
257
249
});
250
+ });
258
251
```
259
252
260
253
You may also use ` setErrorInterceptor ` if you are using Restangular.
261
254
262
255
### Multiple pollers
263
256
``` javascript
264
- // Inject angular poller service.
265
- var myModule = angular .module (' myApp' , [' emguo.poller' ]);
266
-
267
257
myModule .controller (' myController' , function ($scope , poller ) {
268
258
269
259
var poller1 = poller .get (target1),
@@ -288,9 +278,6 @@ myModule.controller('myController', function($scope, poller) {
288
278
289
279
### Multiple controllers
290
280
``` javascript
291
- // Inject angular poller service.
292
- var myModule = angular .module (' myApp' , [' emguo.poller' ]);
293
-
294
281
myModule .factory (' myTarget' , function () {
295
282
// return $resource object, Restangular object or $http url.
296
283
return ... ;
@@ -332,8 +319,6 @@ var myPoller = poller.get(myTarget, {
332
319
You can also use ` pollerConfig ` to set ` smart ` globally for all pollers.
333
320
334
321
``` javascript
335
- var myModule = angular .module (' myApp' , [' emguo.poller' ]);
336
-
337
322
myModule .config (function (pollerConfig ) {
338
323
pollerConfig .smart = true ;
339
324
});
@@ -348,8 +333,6 @@ But if you do want to have more than one poller running against the same target,
348
333
poller on calling ` poller.get ` like so:
349
334
350
335
``` javascript
351
- var myModule = angular .module (' myApp' , [' emguo.poller' ]);
352
-
353
336
myModule .config (function (pollerConfig ) {
354
337
pollerConfig .neverOverwrite = true ;
355
338
});
@@ -358,8 +341,6 @@ myModule.config(function(pollerConfig) {
358
341
### Automatically stop all pollers when navigating between views
359
342
In order to automatically stop all pollers when navigating between views with multiple controllers, you can use ` pollerConfig ` .
360
343
``` javascript
361
- var myModule = angular .module (' myApp' , [' emguo.poller' ]);
362
-
363
344
myModule .config (function (pollerConfig ) {
364
345
pollerConfig .stopOn = ' $stateChangeStart' ; // If you use ui-router.
365
346
pollerConfig .stopOn = ' $routeChangeStart' ; // If you use ngRoute.
@@ -371,8 +352,6 @@ You also have the option to set `pollerConfig.stopOn` to `$stateChangeSuccess` o
371
352
You can also use ` pollerConfig ` to automatically reset all pollers when navigating between views with multiple controllers.
372
353
It empties poller registry in addition to stopping all pollers. It means ` poller.get ` will always create a new poller.
373
354
``` javascript
374
- var myModule = angular .module (' myApp' , [' emguo.poller' ]);
375
-
376
355
myModule .config (function (pollerConfig ) {
377
356
pollerConfig .resetOn = ' $stateChangeStart' ; // If you use ui-router.
378
357
pollerConfig .resetOn = ' $routeChangeStart' ; // If you use ngRoute.
@@ -384,8 +363,6 @@ You also have the option to set `pollerConfig.resetOn` to `$stateChangeSuccess`
384
363
Use the ` handleVisibilityChange ` option to automatically slow down poller delay to ` idleDelay ` when page is hidden.
385
364
By default ` idleDelay ` is set to 10 seconds.
386
365
``` javascript
387
- var myModule = angular .module (' myApp' , [' emguo.poller' ]);
388
-
389
366
myModule .config (function (pollerConfig ) {
390
367
pollerConfig .handleVisibilityChange = true ;
391
368
});
0 commit comments