Is it possible to await an rxjs observable without changing to Promises? I am doing 6 requests OnInit() however, some of the requests finish before another, the order matters. Is it possible to await an observable in typescrypt? All functions look the same, they just make a different request to the server. Thanks for the help :) Here's my code:
I managed to achieve it by chaining the request( calling next request after I get the response from the previous one, however, that solution was not efficient and looked ugly)
ngOnInit() {
this.userId = this.auth.getUserId();
this.getTrendingRentals();
this.getFollowingRentals();
...
this.getLuxuryRentals();
//console.log(this.totalRentals);
}
private getTrendingRentals() {
const rentalObservable = this.rentalService.getRentals();
//Subscribe to service observer
rentalObservable.subscribe((rentals: Rental[]) => {
this.trendingRentals = rentals;
this.totalRentals.push(this.trendingRentals);
}, (err) => {
}, () => {
});
}
public getLuxuryRentals(): Observable<any>{
return this.http.get('/api/v1/rentals/luxury');
}