X-Git-Url: https://juplo.de/gitweb/?p=examples%2Fangular-tour-of-heroes;a=blobdiff_plain;f=src%2Fapp%2Fhero.service.ts;fp=src%2Fapp%2Fhero.service.ts;h=6df713db1826ca67060f377bc78cd97e373fd973;hp=75a002b12d73f9bd7180590dfd9835b254ac8bc9;hb=3efe152e8e2be6f2dc172cf1ac476e2cb01be54b;hpb=510245b57541ddce833a1d76ae2953f12f80fb33 diff --git a/src/app/hero.service.ts b/src/app/hero.service.ts index 75a002b..6df713d 100644 --- a/src/app/hero.service.ts +++ b/src/app/hero.service.ts @@ -13,6 +13,9 @@ import { catchError, tap } from 'rxjs/operators'; export class HeroService { heroesUrl = 'api/heroes'; // URL to web api + httpOptions = { + headers: new HttpHeaders({ 'Content-Type': 'application/json' }) + }; constructor( private http: HttpClient, @@ -38,6 +41,14 @@ export class HeroService { ); } + /** PUT: update the hero on the server */ + updateHero(hero: Hero): Observable { + return this.http.put(this.heroesUrl, hero, this.httpOptions).pipe( + tap(_ => this.log(`updated hero id=${hero.id}`)), + catchError(this.handleError('updateHero')) + ); + } + /** * Handle Http operation that failed. * Let the app continue.