Skip to content

Instantly share code, notes, and snippets.

@nerdic-coder
Created May 11, 2018 21:17
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/7f8cd3d0d629b451abc26723d98c1869 to your computer and use it in GitHub Desktop.
Save nerdic-coder/7f8cd3d0d629b451abc26723d98c1869 to your computer and use it in GitHub Desktop.
getHeroesHttp.ts
getHeroes(): Observable<Hero[]> {
return Observable.create((observer) => {
const xhr = new XMLHttpRequest();
xhr.open('GET', CONFIG.SERVER_URL + 'heroes');
xhr.onload = () => {
if (xhr.status === 200) {
this.messageService.add(`HeroService: fetched heroes`);
observer.next(JSON.parse(xhr.responseText));
}
else {
observer.error(xhr.response);
}
};
xhr.send();
});
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment