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
This commit is contained in:
ryncdr
2025-04-04 00:45:00 -04:00
committed by kirjs
parent e90daf3eb9
commit f22c72b74b
2 changed files with 5 additions and 2 deletions
@@ -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.
<docs-code header="" path="adev/src/content/tutorials/first-app/steps/14-http/src-final/app/housing.service.ts" visibleLines="[15,18]"/>
@@ -13,8 +13,9 @@ export class HousingService {
}
async getHousingLocationById(id: number): Promise<HousingLocation | undefined> {
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) {