2016-03-07 87 views
1

我正在使用節點js rest api。在認證過程中,api返回一個訪問令牌。我需要將訪問令牌添加到來自公共場所的每個請求。在Angular js的每個請求頭添加訪問令牌

+1

http://stackoverflow.com/questions/23244809/angular-js-set-token-on-header - 默認 –

+0

看看角度js攔截器,這將滿足您的要求。使用攔截器,您可以在將請求發送給服務器之前攔截請求,並在返回響應後返回相同的響應 – Sherlock

+0

感謝您的快速響應。是的,這是我需要的。 – Dushantha

回答

1

您可以使用http interceptor
代碼看起來如下

$httpProvider.interceptors.push(function($q, $cookies) { 
    return { 
    'request': function(config) { 
     config.headers['Token'] = $cookies.loginTokenCookie; 
     return config; 
    } 
    }; 
}); 

From this post