2016-05-13 29 views

答えて

0

あなたが設定でそれを行う必要があります(あなたがファイルをapp.js)、またはあなたにもあなたが作成することができます

app.run(['$http', function($http) { 
    $http.defaults.headers.common['Authorization'] = /* ... */; 
}]); 

app.config(['$httpProvider', function($httpProvider) { 
    $httpProvider.defaults.headers.common['Authorization'] = /* ... */; 
}]) 
+0

基本認証とパブリックキーとプライベートキーのようなキーを角度コントローラーに渡すにはどうすればよいですか? ['認証'] = '基本' +ログイン+ ':' +パスワード); – fahad

+0

.controller( 'コントローラ名'、['$ http'、function($ http){ $ http.defaults.headers.common [ }]); – Wcan

+0

また、ファクトリを工場から作り、ファクトリ内のconfigを使ってヘッダを送信することもできます – Wcan

1

あなたのコントローラでそれを行うことができhttpProviderインターセプター:

angular.module('app').factory('apiInterceptor', function(token){ 
    return { 
     request: function(req) { 
      req.headers.Authorization = token.get(); 
      return req; 
     } 
    }).config(function($httpProvider){ 
     $httpProvider.interceptors.push('apiInterceptor'); 
    }).provider('token', function() { 
     var token = ''; 
     return { 
      get: function() { 
       return token; 
      }, 
      set: function(t) { 
       token = t; 
      } 
     } 
    }).controller('myController', function(token) { 
     token.set('your token'); 
    }); 

このようなもの。

+0

基本認証とパブリックキーとプライベートキーのようなキーを角度コントローラに渡すにはどうすればいいですか? – fahad

+0

あなたの情報を保持する角度プロバイダを作成することができます。 – Grissom

関連する問題