1

In my Angular-13 project, I am trying to get the data from API endpoint for chartjs. I have this in the service:

  getCurrentEmployeeChart() {
    return this.http.get(this.baseUrl + 'current-employee')
        .toPromise()
        .then((data) => {
          return data;
        });
  }

I got this error:

'(): Promise<Object | undefined>' is deprecated.ts(6385) Observable.d.ts(125, 9): The declaration was marked as deprecated here.

Then:

toPromise()

is crossed.

How do I resolve this?

Thanks

midowu
  • 937
  • 5
  • 19
  • 40

1 Answers1

1

See this: https://rxjs.dev/deprecations/to-promise

Most likely you want to use lastValueFrom

import { interval, lastValueFrom } from 'rxjs';
import { take } from 'rxjs/operators';

async function execute() {
  const source$ = interval(2000).pipe(take(10));
  const finalNumber = await lastValueFrom(source$);
  console.log(`The final number is ${finalNumber}`);
}
Joel
  • 261
  • 1
  • 6