Skip to content

Instantly share code, notes, and snippets.

@senthilmpro
Created November 21, 2019 22:25
Show Gist options
  • Save senthilmpro/6a3293ecdb4c1e9cc6456ca606f602e0 to your computer and use it in GitHub Desktop.
Save senthilmpro/6a3293ecdb4c1e9cc6456ca606f602e0 to your computer and use it in GitHub Desktop.
async-await-es6-angular.js
import { Injectable } from '@angular/core';
import { HttpClient } from '@angular/common/http';
@Injectable({
providedIn: 'root'
})
export class AuthService {
httpClient : HttpClient;
constructor(httpClient : HttpClient) {
this.httpClient = httpClient;
}
// get data using ES6 await async in Angular 7/8/9
async getData(url, postData){
const data = await this.httpClient.post(url, postData).toPromise();
console.log(data);
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment