我有这样的代码。但那会返回OLD令牌,虽然我的服务器有NEW令牌。
function stores() {
return $http.get(URL + 'stores').then(function(response){
console.log(response.config.headers.Authorization);
});
}
以下代码返回NEW令牌,因为我的服务器最后生成。这就是我想要的。
function stores() {
return $http.get(URL + 'stores').success(function(data, status, headers, config){
console.log(headers('Authorization'));
});
}
问题是,我怎么能用.then方法做到这一点?我看看$ http doc,他们说.success将会减少
答案 0 :(得分:1)
您的问题与您访问标题的方式有关。响应对象具有以下属性(from Angular docs):
.manualNotification #recipientsTab .email-row {
margin-top: 5px;
margin-bottom: 5px;
}
.manualNotification #recipientsTab .email-row label {
display: inline-block;
width: 50px;
text-align: center;
}
.manualNotification #recipientsTab .email-row a {
position: absolute;
width: 50px;
right: 10px;
margin-left: 10px;
}
- 使用转换函数转换的响应主体。{string|Object}
- 响应的HTTP状态代码。{number}
- 标题获取功能。{function([headerName])}
- 用于生成请求的配置对象。{Object}
- 响应的HTTP状态文本。像这样访问标题:
{string}
答案 1 :(得分:0)
非常确定,因为.then
需要两个回调函数。一次成功,一次失误。像这样:
$http.get( URL + 'stores').then(function(res){
$scope.var = res.data;
},function(){})