This commit is contained in:
2021-01-14 13:23:12 +01:00
parent 9570bef24d
commit 1b756cc090
2 changed files with 1486 additions and 1492 deletions

File diff suppressed because it is too large Load Diff

View File

@ -5,6 +5,7 @@ import { HttpClient } from '@angular/common/http';
import { Hero } from './hero'; import { Hero } from './hero';
import { MessageService } from './message.service'; import { MessageService } from './message.service';
import { HEROES } from './mock-heroes'
@Injectable({ @Injectable({
providedIn: 'root' providedIn: 'root'
@ -14,12 +15,14 @@ export class HeroService {
getHeroes(): Observable<Hero[]> { getHeroes(): Observable<Hero[]> {
this.messageService.add('HeroService: fetched heroes'); this.messageService.add('HeroService: fetched heroes');
return this.http.get<Hero[]>(`/heroes`) return of(HEROES)
// return this.http.get<Hero[]>(`/heroes`)
} }
getHero(id: number): Observable<any> { getHero(id: number): Observable<any> {
this.messageService.add(`HeroService: fetch hero id=${id}`); this.messageService.add(`HeroService: fetch hero id=${id}`);
return this.http.get<Hero>(`/hero?id=${id}`) return of(HEROES.find(hero => hero.id === id))
// return this.http.get<Hero>(`/hero?id=${id}`)
} }
updateHero(hero: Hero): Observable<any> { updateHero(hero: Hero): Observable<any> {