我想做somtehing這樣的:角:混合供應商和定製服務模塊的config /運行
angular.module('app', []).config(
[ '$httpProvider', 'customAuthService',
($httpProvider, customAuthService) ->
$httpProvider.defaults.transformRequest.push (data) ->
if customAuthService.isLoggedIn
data['api_key'] = {token: @token}
])
據Angularjs doc,我不能這樣做在我module
的config
塊,由於定製服務是不允許在那裏,我也不能做到這一點在run
塊,因爲像$httpProvider
提供商不準有:
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.
我該怎麼做才能增加我的一些配置依靠自制服務?
我確實最終配置了'$ http'而不是'$ httpProvider',就我的用例而言,它提供了完全相同的值。謝謝。 – 2013-07-24 22:22:42
任何使用'angular.injector'並獲得相同的服務實例的方法,您將調用'config(...)'方法使用該模塊? – 2013-08-08 20:30:04