Created
August 21, 2018 05:44
-
-
Save sarfarazansari/c3c5fa191145810de7d1364c4191b842 to your computer and use it in GitHub Desktop.
using promise with angular httpclient
This file contains hidden or 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
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