From f22c72b74ba93035355ac4c5ab4cc4f35e29ee7e Mon Sep 17 00:00:00 2001 From: ryncdr <92732851+ryncdr@users.noreply.github.com> Date: Fri, 4 Apr 2025 00:45:00 -0400 Subject: [PATCH] docs(docs-infra): first-app tutorial - step-14-http src-final correction (#60738) Updated housing.service.ts > getHousingLocationById() - Added search parameter to fetch URL - Returns single object instead of array PR Close #60738 --- adev/src/content/tutorials/first-app/steps/14-http/README.md | 2 ++ .../first-app/steps/14-http/src-final/app/housing.service.ts | 5 +++-- 2 files changed, 5 insertions(+), 2 deletions(-) diff --git a/adev/src/content/tutorials/first-app/steps/14-http/README.md b/adev/src/content/tutorials/first-app/steps/14-http/README.md index 18f49c26688..52086b25f68 100644 --- a/adev/src/content/tutorials/first-app/steps/14-http/README.md +++ b/adev/src/content/tutorials/first-app/steps/14-http/README.md @@ -169,6 +169,8 @@ The data source has been configured, the next step is to update your web app to HELPFUL: For this example, the code uses `fetch`. For more advanced use cases consider using `HttpClient` provided by Angular. 1. Update the `getHousingLocationsById` function to make a call to the web server you configured. + + HELPFUL: Notice the `fetch` method has been updated to _query_ the data for location with a matching `id` property value. See [URL Search Parameter](https://developer.mozilla.org/en-US/docs/Web/API/URL/search) for more information. diff --git a/adev/src/content/tutorials/first-app/steps/14-http/src-final/app/housing.service.ts b/adev/src/content/tutorials/first-app/steps/14-http/src-final/app/housing.service.ts index fd46318cfc6..35e2c52a3ef 100644 --- a/adev/src/content/tutorials/first-app/steps/14-http/src-final/app/housing.service.ts +++ b/adev/src/content/tutorials/first-app/steps/14-http/src-final/app/housing.service.ts @@ -13,8 +13,9 @@ export class HousingService { } async getHousingLocationById(id: number): Promise { - const data = await fetch(`${this.url}/${id}`); - return (await data.json()) ?? {}; + const data = await fetch(`${this.url}?id=${id}`); + const locationJson = await data.json(); + return locationJson[0] ?? {}; } submitApplication(firstName: string, lastName: string, email: string) {