mirror of
https://github.com/angular/angular.git
synced 2026-09-14 13:54:52 +08:00
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:
@@ -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) {
|
||||
|
||||
Reference in New Issue
Block a user