嘗試向我的CustomExceptionHandler注入服務時,Angular注入器找不到該服務。當加載CustomExceptionHandler時,Angular 2注入器無法找到服務
錯誤:Uncaught Can't resolve all parameters for CustomExceptionHandler: (?).
的設置:
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
}
}
app.module
@NgModule({
declarations: [
...
],
imports: [
...
],
providers: [
ServiceA,
{ provide: ExceptionHandler, useClass: CustomExceptionHandler },
],
bootstrap: [AppComponent],
})
export class AppModule { }
'進口{}服務從 '../服務/ a.service';'也許應該是'進口{ '../services/a.service';'(缺少服務名稱中的'A')ServiceA} –