their initialization, you can only decorate objects in your app’s config block. $provide.decorate makes the $delegate provider available to you. This is an alias to the original instance of the service you’re decorating. Decorator functions are called only one time. Decorators from included modules are NOT reset to the original instance.
var oldDefer = $delegate.defer;! ! // Promises are generated in as each deferred is resolved so we have to wrap! // the deferred creation method in order to access it's promise.! $delegate.defer = function() {! var dfd = oldDefer.call($delegate, arguments);! dfd.promise.success = function(fn) {! return dfd.promise.then(fn, angular.noop);! };! ! dfd.promise.error = function(fn) {! return dfd.promise.then(angular.noop, fn);! };! return dfd;! };! ! return $delegate;! }]);!
into ngStorage's localStorage! $provide.decorator('$localStorage', ['$delegate', function($delegate) {! ! // Save the original function so that we can use the default behavior if the new logic! // isn't needed.! var originalReset = $delegate.$reset;! $delegate.$reset = function(items, prefix) {! if (!prefix) {! return originalReset(items);! }! ! /* Original reset code.! for (var k in this) {! '$' === k[0] || delete this[k];! }*/! ! for (var k in this) {! '$' === k[0] || prefix === k.slice(0, prefix.length) || delete this[k];! }! ! return this;! };! ! return delegate;! }]);!
{! var inFlight = {}; // We'll store the promises of pending requests here.! var originalRecipe = $http.get;! ! $http.get = function() {! // serialize the incoming arguments.! // check to see if inFlight[serialized] exists - if so, return it.! // otherwise invoke originalRecipe with the passed arguments.! // store and return the invoked response.! // Clean up the inFlight hash as requests are completed.! };! }]);! THE ACTUAL CODE FOR THIS IS VERY VERY LONG.