Skip to content

Instantly share code, notes, and snippets.

Embed
What would you like to do?
getHeroHttp.ts
getHero(id: number): Observable<Hero> {
return Observable.create((observer) => {
const xhr = new XMLHttpRequest();
xhr.open('GET', CONFIG.SERVER_URL + `heroes/${id}`);
xhr.onload = () => {
if (xhr.status === 200) {
this.messageService.add(`HeroService: fetched hero with id:${id}`);
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
You can’t perform that action at this time.