小编bfc*_*ara的帖子

AngularJS:每次启动ajax调用时都需要触发事件

每次启动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');
    });
});
Run Code Online (Sandbox Code Playgroud)

事件'httpCallStarted'它没有被解雇.我怀疑在配置块中使用$ rootScope或任何其他实例服务是不正确的.如果是这样,我怎样才能在每次启动http调用时获取事件,而不必在每次拨打电话时都传递配置对象?

提前致谢

angularjs

16
推荐指数
3
解决办法
2万
查看次数

标签 统计

angularjs ×1