Skip to content

Instantly share code, notes, and snippets.

@weeksdev
Last active March 28, 2019 14:01
Show Gist options
  • Save weeksdev/a3b216fc7c4fd3f71205854d889ff824 to your computer and use it in GitHub Desktop.
Save weeksdev/a3b216fc7c4fd3f71205854d889ff824 to your computer and use it in GitHub Desktop.
Angular Promise and then using async/await
// 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