Chciałbym zrobić somtehing tak:kątowa: Mieszanie usługodawcy i niestandardowe usługi w konfiguracji modułu/run
angular.module('app', []).config(
[ '$httpProvider', 'customAuthService',
($httpProvider, customAuthService) ->
$httpProvider.defaults.transformRequest.push (data) ->
if customAuthService.isLoggedIn
data['api_key'] = {token: @token}
])
Według Angularjs doc, nie mogę tego zrobić w bloku config
z moich module
, ponieważ usługi niestandardowe nie są dozwolone tam, ani nie mogę zrobić go w bloku run
, bo jak $httpProvider
dostawcy nie są tam dozwolone:
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.
Jak mogę dodać trochę konfigurację w moim $httpProvider
, która polega na usłudze domowej?
Skonfigurowałem '$ http' zamiast' $ httpProvider', który zapewnia dokładnie taką samą wartość, o ile chodzi o mój przypadek użycia. Dzięki. –
Jakikolwiek sposób użycia 'kątowego injektora' i uzyskanie tej samej instancji usługi, która będzie używana przez moduł, który wywołujesz metodą' config (...) '? –