updateHero.ts
/** PUT: update the hero on the server */ | |
updateHero(hero: Hero): Observable<any> { | |
return Observable.create((observer) => { | |
const xhr = new XMLHttpRequest(); | |
xhr.open('PUT', CONFIG.SERVER_URL + `heroes/${hero.id}`, true); | |
xhr.setRequestHeader('Content-type','application/json; charset=utf-8'); | |
xhr.onload = () => { | |
if (xhr.status === 200) { | |
this.messageService.add(`HeroService: updated hero with id:${hero.id}`); | |
observer.next(JSON.parse(xhr.responseText)); | |
} | |
else { | |
observer.error(xhr.response); | |
} | |
}; | |
xhr.send(JSON.stringify(hero)); | |
}); | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment