+ constructor(
+ private http: HttpClient,
+ private messageService: MessageService) { }
+
+ getHeroes(): Observable<Hero[]> {
+ this.log('fetching heroes...');
+ return this.http.get<Hero[]>(this.heroesUrl);
+ }
+
+ getHero(id: number): Observable<Hero> {
+ this.log(`requested hero id=${id}`);
+ const found: Hero | undefined = HEROES.find(hero => hero.id === id);
+ if (found === undefined) {
+ return EMPTY;
+ } else {
+ return of(found);
+ }
+ }
+
+ /** Log a HeroService message with the MessageService */
+ private log(message: string) {
+ this.messageService.add(`HeroService: ${message}`);