angular component testing promises returning promises code example

Example 1: use promise in angular 8

private fetchData(){
    const promise = this.httpClient.get(this.apiUrl).toPromise();
    console.log(promise);  
    promise.then((data)=>{
      console.log("Promise resolved with: " + JSON.stringify(data));
    }, (error)=>{
      console.log("Promise rejected with " + JSON.stringify(error));
    })
  }

Example 2: use promise in angular 8

private fetchData(){
    const promise = this.httpClient.get(this.apiUrl).toPromise();
    console.log(promise);       
  }