2017-03-07 16 views
1

私は基本的に私はangularjsインターセプタを持つすべての$のHTTPリクエストをチェックすると、angularjsに非常に新しいです、応答データの一致401は、そのページにログインすることをリダイレクトする場合角度迎撃チェック応答データ

すべてのヘルプは

+0

どのバージョンをお使いですか? – vinagreti

+0

@vinagretiごめんなさい...それは角バージョン1.5です –

答えて

2
を高く評価

インターセプタの詳細はhereです。

要するに、メインモジュールの設定セクションに次のコードを書くことができます。

$httpProvider.interceptors.push(function($q, dependency1, dependency2) { 
    return { 
    response: function(response){ 
     return promise.then(
     function success(response) { 
     return response; 
     }, 
     function error(response) { 
     if(response.status === 401){ 
      //your redirection code goes here 
      return $q.reject(response); 
     } 
     else{ 
      return $q.reject(response); 
     } 
     }); 
    } 
    } 
}); 
関連する問題