在我的角-13项目中,我试图从API端点获取图表的数据。我在服务中有这个:
getCurrentEmployeeChart() {
return this.http.get(this.baseUrl + 'current-employee')
.toPromise()
.then((data) => {
return data;
});
}
我发现了一个错误:
'():Promise‘是deprecated.ts(6385) Observable.d.ts(125,9):声明在这里被标记为不推荐使用。 然后: toPromise() 是交叉的。 我该怎么解决这个问题? 谢谢
发布于 2022-01-27 12:26:17
参见:https://rxjs.dev/deprecations/to-promise
很可能您想要使用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}`);
}
https://stackoverflow.com/questions/70878436
复制相似问题