summary |
shortlog |
log |
commit | commitdiff |
tree
raw |
patch |
inline | side by side (from parent 1:
510245b)
i) Heroes and HTTP - Update heroes
+<button (click)="save()">save</button>
<button (click)="goBack()">go back</button>
<button (click)="goBack()">go back</button>
+ save(): void {
+ this.heroService.updateHero(this.hero)
+ .subscribe(() => this.goBack());
+ }
+
goBack(): void {
this.location.back();
}
goBack(): void {
this.location.back();
}
- describe('#getHero', () => {
+ describe('#getHero', () => {
it('should return an empty observable for an invalid id', () => {
it('should return an empty observable for an invalid id', () => {
export class HeroService {
heroesUrl = 'api/heroes'; // URL to web api
export class HeroService {
heroesUrl = 'api/heroes'; // URL to web api
+ httpOptions = {
+ headers: new HttpHeaders({ 'Content-Type': 'application/json' })
+ };
constructor(
private http: HttpClient,
constructor(
private http: HttpClient,
+ /** 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'))
+ );
+ }
+
/**
* Handle Http operation that failed.
* Let the app continue.
/**
* Handle Http operation that failed.
* Let the app continue.