angular - Kako pokrenuti asinhronu funkciju izvan ngZone?
Pokušao sam pokrenuti skriptu izvan trenutne zone:
async ngAfterViewInit(): Promise<void> {
this.ngZone.runOutsideAngular(() => {
await this.run();
});
}
async run() { // TODO }
Dobivam ovu pogrešku:
'await' expressions are only allowed within async functions and at the top levels of modules.ts
Odgovor #1
Funkcija ngAfterViewInit asinhrona je, ali zatim ste koristili this.ngZone.runOutsideAngular s neasinhronom povratnom funkcijom.
Tvoj kod treba izgledati ovako...
ngAfterViewInit(): void {
this.ngZone.runOutsideAngular(async () => {
await this.run();
});
}
async run() { // TODO }
