每次启动 ajax 调用时,我都试图在 $rootScope 上触发一个事件。
var App = angular.module('MyApp');
App.config(function ($httpProvider) {
//add a transformRequest to preprocess request
$httpProvider.defaults.transformRequest.push(function () {
//resolving $rootScope manually since it's not possible to resolve instances in config blocks
var $rootScope = angular.injector(['ng']).get('$rootScope');
$rootScope.$broadcast('httpCallStarted');
var $log = angular.injector(['ng']).get('$log');
$log.log('httpCallStarted');
});
});
事件“httpCallStarted”没有被触发。我怀疑在配置块中使用 $rootScope 或任何其他实例服务是不正确的。如果是这样,我如何在每次启动 http 调用时获取事件,而不必在每次调用时传递配置对象?
提前致谢