I'd like to do somtehing like that:
angular.module('app', []).config(
[ '$httpProvider', 'customAuthService',
($httpProvider, customAuthService) ->
$httpProvider.defaults.transformRequest.push (data) ->
if customAuthService.isLoggedIn
data['api_key'] = {token: @token}
])
According to Angularjs doc, I can't do it in the config
block of my module
, because custom services are not allowed there, nor can I do it in the run
block, because providers like $httpProvider
aren't allowed there:
Configuration blocks - get executed during the provider registrations and configuration phase. Only providers and constants can be injected into configuration blocks. This is to prevent accidental instantiation of services before they have been fully configured.
Run blocks - get executed after the injector is created and are used to kickstart the application. Only instances and constants can be injected into run blocks. This is to prevent further system configuration during application run time.
How can I do to add some configuration in my $httpProvider
that relies on a home-made service ?