gpt4 book ai didi

javascript - 循环依赖,当 ovveriding ExceptionHandler

转载 作者:行者123 更新时间:2023-11-30 16:01:59 25 4
gpt4 key购买 nike

<分区>

我有这个代码:

import {Injectable, ExceptionHandler, SkipSelf, Host, Optional} from     '@angular/core';
import {ToastNotification} from '../toast-messages/toastNotification.service';

export class UIError extends Error {
constructor (private toastMessage: string) {
super();
this.toastMessage = toastMessage;
}
}

export class MyUIError extends UIError {}
export class AnotherError extends UIError {}

export class _ArrayLogger {
res = [];
log(s: any): void { this.res.push(s); }
logError(s: any): void { this.res.push(s); }
logGroup(s: any): void { this.res.push(s); }
logGroupEnd() {};
}

export class ConsoleLogger {
log(s: any): void {console.log(s);}
}

@Injectable()
export class CustomExceptionHandler extends ExceptionHandler {
constructor(private logger: ConsoleLogger, private toast: ToastNotification) {
super (new _ArrayLogger(), true);
}

call(exception: any, stackTrace = null, reason = null) {
let self = this;
if (exception.originalException instanceof UIError) {
self.toast.Error(exception.originalException.toastMessage);
} else {
this.logger.log(exception);
}
}
}

当我尝试运行它时,我遇到了 toast 问题:ToastNotification。我得到的错误是:

zone.js:260Uncaught EXCEPTION: Error during instantiation of ApplicationRef_! (ApplicationRef -> ApplicationRef_).
ORIGINAL EXCEPTION: Cannot instantiate cyclic dependency! (ExceptionHandler -> ToastNotification)
ORIGINAL STACKTRACE:
Error: DI Exception
at CyclicDependencyError.BaseException

我也在 boostrap 中注入(inject)了这个组件。如何解决?

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com