add less 6 Get hero by id
This commit is contained in:
parent
01299fd1e9
commit
299aeb7d14
|
@ -31,12 +31,15 @@ export class HeroService {
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
/** GET hero by id. Will 404 if id not found */
|
||||||
getHero(id: number): Observable<Hero> {
|
getHero(id: number): Observable<Hero> {
|
||||||
// For now, assume that a hero with the specified `id` always exists.
|
const url = `${this.heroesUrl}/${id}`;
|
||||||
// Error handling will be added in the next step of the tutorial.
|
return this.http.get<Hero>(url).pipe(
|
||||||
const hero = HEROES.find(h => h.id === id)!;
|
tap(_ => this.log(`fetched hero id=${id}`)),
|
||||||
this.messageService.add(`HeroService: fetched hero id=${id}`);
|
catchError(this.handleError<Hero>(`getHero id=${id}`))
|
||||||
return of(hero);
|
);
|
||||||
}
|
}
|
||||||
|
|
||||||
/** Log a HeroService message with the MessageService */
|
/** Log a HeroService message with the MessageService */
|
||||||
|
|
Loading…
Reference in New Issue