I am facing an issue with my service where I need to share the result of a forkjoin, but the component is showing up as undefined
Here is my service logic layer:
@Injectable({
providedIn: 'root'
})
export class CoreStateService {
private subject = new BehaviorSubject<any>([]);
hasError$: Observable<any> = this.subject.asObservable();
constructor(private api: HomeGuardService) {}
public verifyFailed(): Observable<any>{
return forkJoin([this.api.getPerfilNew$, this.api.getPosicaoConsolidada()])
.pipe(
catchError(err => {
this.statusError = err.status;
console.log('--->', this.statusError);
return of([]);
}),
map(([perfilInvestors, position]) => {
this.perfilInvestors = perfilInvestors;
this.investments = position;
//verify if perfil failed
if (this.statusError) {
this.perfilFailed = true
} else {
this.perfilFailed = false
}
//verify if investments failed
if (this.investments) {
this.hasInvestiments = true;
}
//combine investments and statusError
this.hasError$ = combineLatest([this.statusError, this.hasInvestiments])
.pipe(
map(([statusError, hasInvestiments]) => statusError && !hasInvestiments)
);
}),
tap(hasError$ => this.subject.next(hasError$)),
);
}
}
And in my component:
constructor(private coreState: CoreStateService) {}
public ngOnInit() {
this.coreState.subscribe(res => {
console.log(res)
})
}
The result in the console can be seen here.
I am looking for a solution to properly handle and return the value of hasError$ in components based on its true or false state.