這個問題在這里已經有了答案: 如何從異步呼叫回傳回應 (42 個回答) 6 天前關閉。
我試圖在當前區域之外調整腳本:
async ngAfterViewInit(): Promise<void> {
this.ngZone.runOutsideAngular(() => {
await this.run();
});
}
async run() { // TODO }
我收到此錯誤:
'await' expressions are only allowed within async functions and at the top levels of modules.ts
uj5u.com熱心網友回復:
ngAfterViewInit 函式是異步的,但是你已經使用了 this.ngZone.runOutsideAngular 和一個非異步回呼函式。
你的代碼需要看起來像這樣......
ngAfterViewInit(): void {
this.ngZone.runOutsideAngular(async () => {
await this.run();
});
}
async run() { // TODO }
轉載請註明出處,本文鏈接:https://www.uj5u.com/caozuo/344616.html
