2016-10-22 7 views
0

私は数週間前にテンプレートを無効にします。データの読み込み時にカスタムスピナー関数を使用する

問題は、サーバーが404または401を返すとき、スピナー($ ionicLoading)が決して隠れないことです。

私はにいくつかのデバッガを入れて、エラーまたはそのいわゆる「spinner.js」

spinner.js

(function() { 
'use strict'; 

angular 
    .module('restaurant') 
    .config(function($httpProvider) { 
     $httpProvider.interceptors.push(function($rootScope, $q) { 
      return { 
       request: function(config) { 
        $rootScope.$broadcast('loading:show'); 
        return config; 
       }, 
       response: function(response) { 
        $rootScope.$broadcast('loading:hide'); 
        return response; 
       }, 
       requestError: function(rejectReason) { 
        debugger; 
        $rootScope.$broadcast('loading:hide'); 
        return $q.reject(rejectReason); 
       } 
      }; 
     }); 
    }) 
    .run(function($rootScope, $ionicLoading) { 
     $rootScope.$on('loading:show', function() { 
      $ionicLoading.show({}); 
     }); 

     $rootScope.$on('loading:hide', function() { 
      debugger; 
      $ionicLoading.hide(); 
     }); 
    }); 
})(); 

のようなものを起これば、私はスピナーを隠す.jsファイルを見つけましたこのスクリプトは、サーバーにデータを要求するときには呼び出されませんでした。このスクリプトを私のコントローラにどのように統合できますか?それともapp.jsに入れる必要がありますか?

ありがとうございます!

答えて

0

あなたのコードにはresponseErrorがありません。400401はサーバーから返され、categorisedはresponseErrorです。

return { 
    request: function(config) { 
     $rootScope.$broadcast('loading:show'); 
     return config; 
    }, 
    response: function(response) { 
     $rootScope.$broadcast('loading:hide'); 
     return response; 
    }, 
    requestError: function(rejectReason) { 
     $rootScope.$broadcast('loading:hide'); 
     return $q.reject(rejectReason); 
    }, 
    responseError: function(rejectReason) { 
     $rootScope.$broadcast('loading:hide'); 
     return $q.reject(rejectReason); 
    } 
}; 
関連する問題