You're mixing the use cases; instantiated services ($http
) cannot be used in the config phase, while providers won't work in run blocks. From the module docs:
- Configuration blocks - […] 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 - […] Only instances and constants can be injected into run
blocks. This is to prevent further system configuration during
application run time.
So use either of the following:
app.run(['$http', function($http) {
$http.defaults.headers.common['Authorization'] = /* ... */;
}]);
app.config(['$httpProvider', function($httpProvider) {
$httpProvider.defaults.headers.common['Authorization'] = /* ... */;
}])
与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…