X-Git-Url: http://juplo.de/gitweb/?a=blobdiff_plain;f=src%2Fapp%2Fhero.service.ts;h=649b856d72174286f9b026a9ead013311b8acb42;hb=fd92a662c471619278e561f25a4beb7ef78d0690;hp=d0801f302c28fedf0cd9c61e92addb21569b27ef;hpb=cdbcd5578c991169816c9b621c5a571ffdaefeb8;p=examples%2Fangular-tour-of-heroes diff --git a/src/app/hero.service.ts b/src/app/hero.service.ts index d0801f3..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'; @@ -13,6 +13,17 @@ export class HeroService { constructor(private messageService : MessageService) { } getHeroes() : Observable { + 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); + } + } }