I'm using a http nested call in angular.
First Call to get a token. Second call will be using token and returning actual data.
public get(api) {
return this.http.get(this.url + '/token')
.map(res => res.json())
.toPromise()
.then((data: any) => {
this.access_token = data.access_token
let headers = new Headers();
headers.append('Authorization', 'Bearer ' + this.access_token);
return this.http.get(this.url + api, {
headers: headers
}).map(res => res.json());
})
}
The function returns Promise<Observable<any>>
. How to parse the response so i can get the data from nested call in a subscription.
this.get('me/profile')
.subscribe(data => {
console.log(data);
});