I have this method in my service.
get trucks() {
if (!this.cache$) {
this.cache$ = this.requestAvailableTrucks().pipe(
shareReplay(CACHE_SIZE)
);
}
return this.cache$;
}
private requestAvailableTrucks() : Observable<Array<any>> {
return this.http.get<any>(API_ENDPOINT_TRUCKS).pipe(
map(response => response.value)
);
}
In my app component I need to initialized my property as the result from the requestAvailableTrucks call. And after that I need to do some logic depending on the result that came from the backend. But the problem is that I don't know how can I await this method.
When I try
ngOnInit() {
this.locations = this.truckService.trucks;
... The other logic ...
}
the other logic don't wait for the method in my service to end.
The only think that can be done is the approach with subscribe, and to put the code there but I need to have my logic in my service and call it from my ts.file like this