Service providers are the parent service type used for factories and services. They are the most configurable and extensible of the service types, and allow you to inspect and modify other service types during the application's initialization.
Service providers take a function parameter that returns an object that has a $get
method. This method is what AngularJS will use to produce the injected value after the application has been initialized. The object wrapping the $get
method is what will be supplied if the service provider is injected into the config
phase. This can be implemented as follows:
(app.js)
angular.module('myApp', [])
.config(function(PlayerProvider) {
// appending 'Provider' to the injectable
// is an Angular config() provider convention
PlayerProvider.configSwapPlayer();
console.log(PlayerProvider.configGetPlayer());
})
.controller('Ctrl', function($scope, Player) {
$scope.data = Player.getPlayer();
$scope.update = Player...