Last active
March 28, 2019 14:01
-
-
Save weeksdev/a3b216fc7c4fd3f71205854d889ff824 to your computer and use it in GitHub Desktop.
Angular Promise and then using async/await
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
// some.service.ts | |
public async getData(): Promise<SomeType> { | |
try { | |
return await this.http.get<SomeType>("api/some/url") | |
.toPromise() | |
} catch (error) { | |
this.handleError(error); | |
return null; | |
} | |
} | |
// some.component.ts | |
this.someData = await this.someService.getData(); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment