2014-09-12 59 views

回答

1

我如何解决它:

服务:

angular.module('mmn') 
    .factory('serverTimeout', function($timeout, $rootScope) { 

    var serverTimeout = { 
     request: function(config) { 
     config.timeout = $timeout(function() { 
      $rootScope.$broadcast('event:serverTimeout'); 
     }, 30000); 

     return config; 
     }, 
     response: function(response) { 
     $timeout.cancel(response.config.timeout); 
     return response; 
     } 
    }; 
    return serverTimeout; 
    }); 

的App.config:

$httpProvider.interceptors.push('serverTimeout'); 

App.run:

//watch serverTimeout event 
    $rootScope.$on('event:serverTimeout', function(){ 
    //your handler here 
    }); 
相关问题