I am currently attempting to pass the outcome of a service layer with regard to components.
The service that connects with the API:
public getPerfilNew$(): Observable<PerfilInvestidor> {
return this.http.get<PerfilInvestidor>(`${environment.api.basePosicaoConsolidada}/consolidado`)
.pipe(
map(res => res),
shareReplay(1),
catchError(err => {
console.log('Error in perfil', err);
return throwError(err);
})
)
}
public getPositionConsolidated(): Observable<PosicaoConsolidada> {
return this.http.get<PosicaoConsolidada>(`${environment.api.basePosicaoConsolidada}/consolidado`)
.pipe(
map(res => res),
shareReplay(1),
catchError(err => {
console.log('Error investiments', err);
return throwError(err);
})
)
}
In my component, I attempted the following:
public loadData() {
// Determine if the profile retrieval failed or not
this.homeGuardService.getPerfilNew$.pipe(
takeUntil(this.unsubscribe)
).subscribe(res => {
this.perfilInvestidor = res;
this.perfilFailed = this.perfilInvestidor.status ? true : false;
console.log('perfil is failed --->', this.perfilFailed)
})
// Checking for investments
this.homeGuardService.getPositionConsolidated().subscribe(res => {
this.positionConsolidated = res
if (this.positionConsolidated) {
this.investments = true
}
});
this.isEverthingFailed = !this.investments && this.perfilFailed
}
I need to subscribe external values and match them into my variable isEverythingFailed. Should I use Subject? BehaviorSubject? Because in this way, the variables investments and perfilFailed are undefined.
With this number of observables, am I compromising memory usage? Open to suggestions.