I have the following search that I try to execute:
I want to search something based on the first id
, this returns a FirebaseListObservable
. I then try to execute code inside the switchMap
function of the Observable
because the search usually takes a bit longer and my code would be finished otherwise and the wrong values for lastLoc
would be used.
I try to run this for a series of points so I loop through an array in the beginning.
Here is my code:
evaluateRoutes() {
this.currentTour.travelDistance = 0;
this.currentTour.travelTime = 0;
this.currentTour.workTime = 0;
const locs = this.currentTour.locIds;
let lastLoc = null;
locs.forEach(loc => {
console.log(lastLoc, loc);
if (lastLoc !== null) {
console.log('if durch', lastLoc, loc);
this.afDb.list('routes', {
query: {
orderByChild: 'idStart',
equalTo: loc
}
}).switchMap(items => {
console.log('switchMap starts', lastLoc, loc);
const filtered = items.filter(item => item.idEnd === lastLoc);
const route = filtered[0];
this.currentTour.routeIds.push(route.$key);
this.currentTour.routes.push({
idEnd: route.idEnd,
idStart: route.idStart,
travelDistance: route.travelDistance,
travelTime: route.travelTime,
tsCreated: route.tsCreated,
userCreated: route.userCreated
});
this.currentTour.travelDistance = +0 + this.currentTour.travelDistance + route.travelDistance;
this.currentTour.travelTime = +0 + this.currentTour.travelTime + route.travelTime;
}).subscribe();
}
lastLoc = loc;
});
}
I receive the following error:
Argument of type '(items: any) => void' is not assignable to parameter of type '(value: any, index: number) => ObservableInput<{}>'.
Type 'void' is not assignable to type 'ObservableInput<{}>'.