Below i am using API to get country region from server using Observable and that country code is saved into sessionStorage():
let options = new RequestOptions({ headers: this.headers });
return this.http.get(this.backendUrl + pathName, options)
.map((res: Response) => {
return res.json();
})
.catch(e => {
if (e.status === 401) {
this.router.navigateByUrl('/error');
return Observable.throw('Unauthorized');
}
});
and below is my another code where i want to use that country region code which is stored in sessionStorage() in post request:
let options = new RequestOptions({ headers: this.headers });
body_val['hash_value'] = root.hashValue;
body_val['region'] = <!-- Region -->;
body_val['client_id'] = 'ABC';
body_val['users_id'] = this.users_id;
if (localStorage.getItem('userdata')) {
let user = JSON.parse(localStorage.getItem('userdata'));
body_val['users_id'] = user.userdata.id;
body_val['userid'] = user.userdata.id;
}
return this.http.post(root.apiUrl + pathName, body_val , options)
.map((res: Response) => {
return res.json();
})
.catch(e => {
if (e.code === 404) {
this.router.navigateByUrl('/error');
return Observable.throw('Unauthorized');
}
});
On first time when i load the page, i am getting null but in second time load the page i am able to get the value of sessionStorage() .How i can achieve first API call data is second API and on first page load.