$http帖子和事件处理

$http post and event handling

本文关键字:事件处理 http      更新时间:2023-09-26

我正在尝试在http请求处理和成功响应之间广播事件,但到目前为止我无法找出解决方案:

$rootScope.$broadcast('transfer:fileTransferInProgress');
$http.post("/api/example", data, {
            transformRequest: angular.identity,
            headers: {'Content-Type': undefined}                   
           }).success(function(response){
               $rootScope.$broadcast('transfer:readyState', response);
          }).error(function(){
              $rootScope.$broadcast('transfer:error');
          });

我想在成功和请求处理之间触发('transfer:fileTransferInProgress')事件。我怎么能做到这一点??

基于注释:

$scope.$on(success || error event, function() {
   if(msg exists) destroy msg
   show new msg
});