Created
May 12, 2018 08:32
-
-
Save nerdic-coder/b2da4e249705d737305ab47253050bb9 to your computer and use it in GitHub Desktop.
getHeroHttp.ts
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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