【发布时间】:2019-12-20 05:38:54
【问题描述】:
我在收到响应后尝试将令牌存储在会话存储中,但是当我编译此代码时出现错误“对象”类型上不存在属性“access_token”。此错误在发送请求之前显示,我想在收到响应而不是在发送请求之前执行 sesssionstorage。
this.http.post(url,null,
{
headers : new HttpHeaders({
'Content-Type': 'application/x-www-form-urlencoded',
'Authorization' :'Basic '+ btoa('username:password')
})
}
).subscribe(
data => { // json data
console.log('Success: ', data);
sessionStorage.setItem("Token ",data.access_token)
},
error => {
console.log('Error: ', error);
}
)
}
【问题讨论】:
-
你可以制作一个stackblitz吗?点击这里制作here
标签: typescript httpclient angular8