From 0be4c2fadcbe88580490112f9f9eb4d413b35269 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Joe=20Ku=CC=88ng?= Date: Sat, 15 Apr 2023 15:08:58 +0200 Subject: [PATCH] fix getWaypoints --- src/app/service/readjson.service.ts | 10 +++++++--- 1 file changed, 7 insertions(+), 3 deletions(-) diff --git a/src/app/service/readjson.service.ts b/src/app/service/readjson.service.ts index b737271..da27017 100644 --- a/src/app/service/readjson.service.ts +++ b/src/app/service/readjson.service.ts @@ -39,18 +39,22 @@ export class ReadjsonService{ ); } -/* + getWaypoints(location: string, id: number): Observable { return this.locations.pipe( map((locations) => { const foundLocation: Locations | undefined = locations.find((loc: Locations) => loc.location === location); - return foundLocation ? foundLocation.waypoints.filter((way: waypoint) => way.id === id) : []; + if (foundLocation?.waypoints) { + return foundLocation ? foundLocation.waypoints.filter((way: waypoint) => way.id === id) : []; + } else { + return []; + } }), tap(data => console.log("data requested", data)) ); } - */ + }