1

I have tried to tun script outside current Zone:

  async ngAfterViewInit(): Promise<void> {
     this.ngZone.runOutsideAngular(() => {
       await this.run();
     });
  }
  
  async run() { // TODO }

I get this error:

'await' expressions are only allowed within async functions and at the top levels of modules.ts
Liam
  • 27,717
  • 28
  • 128
  • 190
  • Does this answer your question? [Syntax for an async arrow function](https://stackoverflow.com/questions/42964102/syntax-for-an-async-arrow-function) – Munzer Oct 25 '21 at 15:25

1 Answers1

4

The ngAfterViewInit function is asynchronous but then you've used this.ngZone.runOutsideAngular with a non asynchronous callback function.

You're code needs to look like this...

ngAfterViewInit(): void {
    this.ngZone.runOutsideAngular(async () => {
        await this.run();
    });
}

async run() { // TODO }
Luke.T
  • 600
  • 1
  • 5
  • 24