Skip to content

Instantly share code, notes, and snippets.

@nerdic-coder
Created May 12, 2018 09:40
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save nerdic-coder/cd62f8ce313c395e2f293046a4778d80 to your computer and use it in GitHub Desktop.
Save nerdic-coder/cd62f8ce313c395e2f293046a4778d80 to your computer and use it in GitHub Desktop.
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