I'am working on an Angular Project and I have a Problem which I didn't mange to solve...
//part of class Data
constructor(private fetchData: FetchData) {
this.subscription = timer(0, 1000000).pipe(
switchMap(() => this.fetchData.getData())
).subscribe((result) => this.data = result);
}
private data: any;
private subscription: Subscription;
public getData(): Object {
return this.data.data_property;
}
It reports errors because of a runtime condition and I want to solve this Problem by waiting for the variable to be filled. The whole app needs it, so it is pretty important. I want to solve it with an Observable from Angulars rxjs but I didn't really got it to work, I'am pretty new to this. By the way, both, the FetchData and the Data Class are @Injectable Services.
If somebody has an additional Tip for me to convert the variable data to a type of Interface e.g. "myData" I would be very happy, too, because I don't want to use the hack with any. Problem is the getData of FetchData returns just an Object from HttpClient:
//part of class FetchData
getData() {
return this.http.get(this.dataUrl)
.pipe(
catchError(this.handleError)
);
}
Tanks for helping anyways. Love Stackoverflow community :D