6: Get Data from a Server
authorKai Moritz <kai@juplo.de>
Sat, 16 May 2020 11:22:28 +0000 (13:22 +0200)
committerKai Moritz <kai@juplo.de>
Sat, 16 May 2020 11:42:51 +0000 (13:42 +0200)
f) Heroes and HTTP - Tap into the Observable

src/app/hero.service.ts

index 90fa42c..f8374b1 100644 (file)
@@ -4,7 +4,7 @@ import { Hero } from './hero';
 import { HEROES } from './mock-heroes';
 import { HttpClient, HttpHeaders } from '@angular/common/http';
 import { MessageService } from './message.service';
-import { catchError } from 'rxjs/operators';
+import { catchError, tap } from 'rxjs/operators';
 
 
 @Injectable({
@@ -23,6 +23,7 @@ export class HeroService {
     return this.http
       .get<Hero[]>(this.heroesUrl)
       .pipe(
+        tap((heroes: Hero[]) => this.log(`fetched ${heroes.length} heroes`)),
         catchError(this.handleError<Hero[]>('getHeroes', []))
       );
   }