当尝试将服务注入我的 CustomExceptionHandler 时,Angular 注入器找不到该服务。
错误:Uncaught Can't resolve all parameters for CustomExceptionHandler: (?).
设置:
自定义异常处理程序
import { ExceptionHandler } from '@angular/core';
import { ServiceA } from '../services/a.service';
export class CustomExceptionHandler extends ExceptionHandler {
constructor(private serviceA: ServiceA) {
super(null, null);
}
call(error, stackTrace = null, reason = null) {
//do something with the service
}
}
应用程序模块
@NgModule({
declarations: [
...
],
imports: [
...
],
providers: [
ServiceA,
{ provide: ExceptionHandler, useClass: CustomExceptionHandler },
],
bootstrap: [AppComponent],
})
export class AppModule { }