-2

问题

ERROR Error: Uncaught (in promise): Error: Loading chunk dashboard.module failed.
Error: Loading chunk dashboard.module failed.

我想用这个

import { Injectable, ErrorHandler } from "@angular/core";

@Injectable()
export class GlobalErrorHandler implements ErrorHandler {
  
  handleError(err: any): void {
    const chunkFailedMessage = /Loading chunk [\d]+ failed/;
    const chunkFailedMessage1 = /Loading chunk dashboard.module failed/;

    console.log('Loading chunk FRT'+ err);
    console.log('Loading chunk FRT'+ err.message);
    if (chunkFailedMessage1.test(err.message)) {
      alert("Se requiere un reinicio para el correcto funcionamiento del sitio");
      window.location.reload();
    }
  }
}

我的项目中有 app.modules.ts --> pages.module.ts --> Child(应该启动 ErrorHandler 的模块)

4

1 回答 1

0

在您的模块中,您应该GlobalErrorHandler在提供者中注册,如下所示,

 providers:[{ provide: ErrorHandler, useClass: GlobalErrorHandler }]
于 2020-08-01T19:26:33.600 回答