角度应用程序使用哨兵来捕获异常。哨兵由工厂提供。我试图在该工厂内使用服务,但无法弄清楚为什么出现此错误:
ERROR in/sfsfsadsf/src/app/app.module.ts(64,12): error TS2554: Expected 1 arguments, but got 0.
其余代码:
//Other imports
import {SentryCaptureErrorService} from '@common/app/services/sentry-capture-error.service';
export class RavenErrorHandler implements ErrorHandler {
constructor(
public sentryCaptureErrorService: SentryCaptureErrorService
) {
}
RavenErrorHandler(error: any): void {
this.sentryCaptureErrorService.sendCapturedException(error, environment, 'app.module')
}
}
export function provideErrorHandler() {
if (
environment.envName === 'local'
) {
return new ErrorHandler();
} else {
return new RavenErrorHandler();
}
}
@NgModule({
declarations: [
AppComponent
],
imports: [],
providers: [
{
provide: ErrorHandler,
useFactory: provideErrorHandler,
deps: [SentryCaptureErrorService],
multi: true,
},
],
bootstrap: [AppComponent],
})
export class AppModule {
constructor(
private sentryCaptureErrorService: SentryCaptureErrorService
) {
this.sentryCaptureErrorService.configAndInstallSentry(environment);
}
}
通过在RavenErrorHandler中包含'sentryCaptureErrorService',我得到了上面提到的错误。我可以将服务注入AppModule类,但不能注入RavenErrorHandler。