2011-07-17 08:05:43 +00:00
|
|
|
'use strict';
|
|
|
|
|
|
2011-02-15 06:12:45 +00:00
|
|
|
/**
|
|
|
|
|
* @workInProgress
|
|
|
|
|
* @ngdoc service
|
|
|
|
|
* @name angular.service.$defer
|
|
|
|
|
* @requires $browser
|
|
|
|
|
*
|
|
|
|
|
* @description
|
2011-05-18 12:16:09 +00:00
|
|
|
* Delegates to {@link angular.service.$browser $browser.defer}, but wraps the `fn` function
|
2011-02-15 06:12:45 +00:00
|
|
|
* into a try/catch block and delegates any exceptions to
|
2011-05-18 12:16:09 +00:00
|
|
|
* {@link angular.service.$exceptionHandler $exceptionHandler} service.
|
2011-02-15 06:12:45 +00:00
|
|
|
*
|
|
|
|
|
* In tests you can use `$browser.defer.flush()` to flush the queue of deferred functions.
|
|
|
|
|
*
|
|
|
|
|
* @param {function()} fn A function, who's execution should be deferred.
|
2011-02-25 19:18:42 +00:00
|
|
|
* @param {number=} [delay=0] of milliseconds to defer the function execution.
|
2011-02-15 06:12:45 +00:00
|
|
|
*/
|
2011-03-23 16:33:29 +00:00
|
|
|
angularServiceInject('$defer', function($browser) {
|
|
|
|
|
var scope = this;
|
2011-02-25 19:18:42 +00:00
|
|
|
return function(fn, delay) {
|
2011-02-15 06:12:45 +00:00
|
|
|
$browser.defer(function() {
|
2011-03-23 16:33:29 +00:00
|
|
|
scope.$apply(fn);
|
2011-02-25 19:18:42 +00:00
|
|
|
}, delay);
|
2011-02-15 06:12:45 +00:00
|
|
|
};
|
2011-08-10 20:15:43 +00:00
|
|
|
}, ['$browser']);
|