でプロバイダとカスタムサービスミキシング:Angularjs docによると:私はそのようsomtehingやってみたいモジュールのconfig /実行
angular.module('app', []).config(
[ '$httpProvider', 'customAuthService',
($httpProvider, customAuthService) ->
$httpProvider.defaults.transformRequest.push (data) ->
if customAuthService.isLoggedIn
data['api_key'] = {token: @token}
])
を、私は私のmodule
のconfig
ブロックでそれを行うことができません、 $httpProvider
のようなプロバイダが存在し許可されていないため、カスタムサービスは、そこに許可されていない、また私はrun
ブロックでそれを行うことができますので:
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.
私はでいくつかの設定を追加するために行うことができますどのように自家製のサービスを利用している?
私は、 '$ httpProvider'の代わりに' $ http'を設定しました。これは、私のユースケースに関する限り、まったく同じ値を提供します。ありがとう。 –
'angular.injector'を使い、' config(...) 'メソッドを呼び出すモジュールが使うサービスインスタンスを得る方法はありますか? –