We need to call multiple REST API from ngOnInit() One by one. After calling first one we need to pass this response in second API call and same for the third one we need to get the value from second API call and pass it third one.
But while calling like below we are getting always undefined value .
this.globalVar1 : any;
this.globalVar2 : any;
this.globalVar3 : any;
async ngOnInit() {
this.apiService.getFirstAPICall(request).subscribe(info => {
this.globalVar1 = info; //here value is coming from API service call
}
console.log(this.globalVar1); //here undefined
//Now calling the second API ** here we need this first variable
//but due to undefined we are getting error
this.apiService.getSecondAPICall(request.globalVar1).subscribe(info => {
this.globalVar2 = info;
}
console.log(this.globalVar2); //here undefined