Reputation: 239
From the post i have got a res as
.subscribe( res => {
let result = JSON.stringify(res);
alert(result)
})
& as the response of alert(result)
I’m getting
{"access_token": "hjhdshJHUHYI67HUjhhk98BJ_BJHBBHbnbhbhbjh_jmnhghmghgfffgxcgfcf98hujh",
"expires_in":"518399"}
Here I want to read the access_token
value & save it in a variable how Can I do it?
Upvotes: 1
Views: 676
Reputation: 638
.subscribe( res => {
alert(res.access_token)
})
If you are unable to solve your problem by following solution..
There is no need to stringify the result. Please try following..
.subscribe( res => {
alert(res['access_token']);
})
Upvotes: 0
Reputation: 222552
You dont have to stringify, just access it as res.access_token
.subscribe((res:any) => {
let result = res.access_token;
alert(result)
})
Upvotes: 2
Reputation: 20414
Just access that property of the object with the usual syntax.
.subscribe( res => {
let the_variable = res['access_token']; //or `result.access_token`
})
Upvotes: 1