2016-05-11 8 views
1

私はAngularJSでトークンベースの認証を実装しています。トークンはサーバー上に作成され、クライアントに返されます。認証後、すべての残りのコールのヘッダーにトークンが追加されます。次のように私のconfig.jsの中でそれを注入しその後AngularJS:httpインターセプタの注入エラー

ristoreApp.factory('authInterceptor', function ($rootScope, $q, $window) { 
    return { 
     request: function (config) { 
      config.headers = config.headers || {}; 
      if ($window.localStorage.getItem("access_token")) { 
       config.headers.Authorization = 'Bearer ' + $window.localStorage.getItem("access_token"); 
      } 
      return config; 
     }, 
     response: function (response) { 
      if (response.status === 401) { 
       // handle the case where the user is not authenticated 
      } 
      return response || $q.when(response); 
     } 
    }; 
}); 

Failed to instantiate module ristoreApp due to: Unknown provider: authInterceptor 

私の方法の何が問題になっている:

ristoreApp 
.config(function ($httpProvider, authInterceptor, $routeProvider) { 

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

    $routeProvider 
....... 
}) 

は、しかし、私は、次のエラーを得た私はauthInterceptorを作成しましたインターセプターを注入するには?

+0

詳細コードを掲載できますか?もしあなたがfiddle/plnkrを追加すれば良いでしょう。 –

答えて

2

これはあなたのルーティングファイルで

ristoreApp

を定義していない時にモジュールが起こるインスタンス化に失敗しました。

関連する問題