我正在尝试在 Angular 2 中实现一个中央 ExceptionHandler。我在 SO 中进行了搜索,发现了几个关于这个主题的主题,如下所示:
模块 '"angular2/angular2"' 没有导出的成员 'ExceptionHandler'
如何正确覆盖angularjs中的exceptionHandler?
但是,这个话题似乎已经过时了。
我正在使用 Angular 2 RC5,并按照此处的文档,我尝试实现:
import { ExceptionHandler } from '@angular/core';
export class CustomExceptionHandler implements ExceptionHandler {
call(error:any, stackTrace:any = null, reason:string = null) {
// do something with the exception
}
}
但我收到类似“TS2420 - CustomExceptionHandler 错误地实现接口 ExceptionHandler。‘CustomExceptionHandler’ 类型中缺少属性‘_logger’。
我是 TS 的新手,但我已经用 Java 编程了 10 年。
实际上,当我在 IDE (IntelliJ) 中单击 ExceptionHandler 时,代码会跟随一个类,而不是一个接口。
export declare class ExceptionHandler {
private _logger;
private _rethrowException;
constructor(_logger: any, _rethrowException?: boolean);
static exceptionToString(exception: any, stackTrace?: any, reason?: string): string;
call(exception: any, stackTrace?: any, reason?: string): void;
}