X-Git-Url: http://juplo.de/gitweb/?a=blobdiff_plain;f=src%2Fapp%2Fhero.service.ts;h=649b856d72174286f9b026a9ead013311b8acb42;hb=fd92a662c471619278e561f25a4beb7ef78d0690;hp=8df8f33af31d49fc5afa8f07ffe10b12a05e8b70;hpb=3daace5a71b0be19e05b74de9cf7530ce6aa92c3;p=examples%2Fangular-tour-of-heroes diff --git a/src/app/hero.service.ts b/src/app/hero.service.ts index 8df8f33..649b856 100644 --- a/src/app/hero.service.ts +++ b/src/app/hero.service.ts @@ -1,5 +1,5 @@ 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'; @@ -16,4 +16,14 @@ export class HeroService { this.messageService.add('HeroService: fetching heroes...'); return of(HEROES); } + + getHero(id: number): Observable { + this.messageService.add(`HeroService: requested hero id=${id}`); + const found: Hero | undefined = HEROES.find(hero => hero.id === id); + if (found === undefined) { + return EMPTY; + } else { + return of(found); + } + } }