Angular 2+ wait for subscribe to finish to update/access variable
问题 Hello I am having an issue with my variables being undefined. I am certain this is because the observable hasnt finished. Here is the part of my code in my .ts file that is causing the issue: (I'm placing the minimum code required to understand the issue, if I need to provide more code and context let me know. Also myFunction gets called from a click event in the html.) export class myClass { myVariable: any; myFunction() { this.myService.getApi().subscribe(data => { this.myVariable = data; }