5: Add In-app Navigation
[examples/angular-tour-of-heroes] / src / app / hero.service.ts
1 import { Injectable } from '@angular/core';
2 import { Observable, of } from 'rxjs';
3 import { Hero } from './hero';
4 import { HEROES } from './mock-heroes';
5 import { MessageService } from './message.service';
6
7
8 @Injectable({
9   providedIn: 'root'
10 })
11 export class HeroService {
12
13   constructor(private messageService : MessageService) { }
14
15   getHeroes() : Observable<Hero[]> {
16     this.messageService.add('HeroService: fetching heroes...');
17     return of(HEROES);
18   }
19
20   getHero(id: number): Observable<Hero> {
21     this.messageService.add(`HeroService: fetched hero id=${id}`);
22     return of(HEROES.find(hero => hero.id === id));
23   }
24 }