6: Get Data from a Server
[examples/angular-tour-of-heroes] / 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', []))
       );
   }