I have a little problem with subscribing my Observable
I have one one combined Observable:
private selectedEntryId$ = new Subject<number>();
private entries$ = new Subject<MappingEntry[]>();
private selectedEntry$ = Observable.combineLatest(
this.entries$,
this.selectedEntryId$,
(entries: MappingEntry[], id: number) => {
return entries.find((entry: MappingEntry) => {
return entry.id === id;
});
});
I try do API call every time, when my selectedEntry$
has next value and subscribe result in this way:
constructor(private checkService: CheckService) {
this.subscribeLengthCalculator();
}
subscribeLengthCalculator() {
this.subscriptions.add(
this.selectedEntry$
.switchMap((entry) => {
return entry ? this.checkService.calculateLinesLength([entry.value]) : Observable.empty();
}).subscribe(([calculation: CalculationObject]) => {
console.log(calculation);
this.calculation = calculation;
})
);
}
First time when selectedEntry$
has next value, console.log
throw to the console correct API result, but in my html calculation
has null value. When selectedEntry$
has second next value, console.log
throw to the console correct API result too but in html show mi previous value. Anyone can explain me this behaviour and tell me what I should do to showing current data in html? It's very strange behaviour.