X-Git-Url: https://juplo.de/gitweb/?a=blobdiff_plain;f=src%2Fapp%2Fhero.service.ts;h=6df713db1826ca67060f377bc78cd97e373fd973;hb=3efe152e8e2be6f2dc172cf1ac476e2cb01be54b;hp=a0b5d5ba94b22f74519d11cca932de424b25d2ed;hpb=cbadc2c63fa11dc938469117ec8f4a65a7873851;p=examples%2Fangular-tour-of-heroes diff --git a/src/app/hero.service.ts b/src/app/hero.service.ts index a0b5d5b..6df713d 100644 --- a/src/app/hero.service.ts +++ b/src/app/hero.service.ts @@ -12,7 +12,10 @@ import { catchError, tap } from 'rxjs/operators'; }) export class HeroService { - private heroesUrl = 'api/heroes'; // URL to web api + 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.