It's been a week and I still can't figure this out. Being new to front-end development, I'm struggling with storing the response from subscribe in a global variable for future use.
ngOnInit(): void {
this.http.get<APIResponse>('url' + globals.applicationId, { headers: httpHeaders })
.pipe(map((res: APIResponse) => res))
.subscribe(res => {
// Storing apiresponse globally
this.apiresponse = res;
console.log(this.apiresponse); // This prints what I need
});
console.log(this.apiresponse); // This prints undefined
}
I know similar questions might have been asked before, but I couldn't find a solution that fits my specific case. Can someone please assist me without closing or marking this question as a duplicate? Thank you!