Skip to content

Instantly share code, notes, and snippets.

@sarfarazansari
Created August 21, 2018 05:44
Show Gist options
  • Save sarfarazansari/c3c5fa191145810de7d1364c4191b842 to your computer and use it in GitHub Desktop.
Save sarfarazansari/c3c5fa191145810de7d1364c4191b842 to your computer and use it in GitHub Desktop.
using promise with angular httpclient
let url = `${YOUR_URL}`;
let promise = new Promise((resolve: any, reject) => {
this._httpClient.get(url).toPromise()
.then(
(res: any) => {
resolve(res);
},
err => {
reject(err);
}
);
});
return promise;
// other way
return this._httpClient.get(url)
.map((res: any) => // do the logic )
.catch(this.handleError)
.toPromise();
private handleError(error: any): Promise<any> {
return Promise.reject(error.message || error);
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment