I am trying to get data from an API. The problem is I want to wait till the data is there before executing the code after.
definObj(obj){
console.log(obj);
}
execute(){
this.service.getData(URL).subscribe(data => this.customerArr = data);
this.defineObj(this.customerArr); // Workaround
...
}
In my service.ts
getData(URL){
return this.http.get(URL);
}
I want that the object is defined without using my workaround. I want the program to wait till the data is received. One would use a resolver when you change the page but here I just want to get some data while staying on the same page.