+ const url = `${this.heroesUrl}/${id}`;
+ return this.http.get<Hero>(url).pipe(
+ tap(_ => this.log(`fetched hero id=${id}`)),
+ catchError(this.handleError<Hero>(`getHero id=${id}`))
+ );
+ }
+
+ /** PUT: update the hero on the server */
+ updateHero(hero: Hero): Observable<any> {
+ return this.http.put(this.heroesUrl, hero, this.httpOptions).pipe(
+ tap(_ => this.log(`updated hero id=${hero.id}`)),
+ catchError(this.handleError<any>('updateHero'))
+ );
+ }
+
+ /* GET heroes whose name contains search term */
+ searchHeroes(term: string): Observable<Hero[]> {
+ if (!term.trim()) {
+ // if not search term, return empty hero array.
+ return of([]);