An often overlooked aspect of AngularJS services is their ability to decorate service types in the initialization logic. This allows you to add or modify how factories or services will behave in the config
phase before they are injected in the application.
In the config
phase, the $provide
service offers a decorator method that allows you to inject a service and modify its definition before it is formally instantiated. This is shown here:
(app.js) angular.module('myApp', []) .config(function($provide) { $provide.decorator('Player', function($delegate) { // $delegate is the Player service instance $delegate.setPlayer('Eli Manning'); return $delegate; }); }) .controller('Ctrl', function($scope, Player) { $scope.data = Player.getPlayer(); $scope.update = Player.swapPlayer; }) .factory('Player', function() { var player = { number: 10 }, swap = function() { player.name = 'DeSean Jackson'; }; return { setPlayer: function...