import { Injectable } from '@angular/core';
-import { Observable, of } from 'rxjs';
+import { Observable, of, EMPTY } from 'rxjs';
import { Hero } from './hero';
import { HEROES } from './mock-heroes';
import { MessageService } from './message.service';
this.messageService.add('HeroService: fetching heroes...');
return of(HEROES);
}
+
+ getHero(id: number): Observable<Hero> {
+ this.messageService.add(`HeroService: fetched hero id=${id}`);
+ const found: Hero | undefined = HEROES.find(hero => hero.id === id);
+ if (found === undefined) {
+ return EMPTY;
+ } else {
+ return of(found);
+ }
+ }
}