我正在尝试ngx-toastr
在我的全局错误处理程序中使用,但它给了我以下错误。
Error: Cannot instantiate cyclic dependency! ApplicationRef
at throwCyclicDependencyError (core.js:8072)
at R3Injector.hydrate (core.js:17049)
at R3Injector.get (core.js:16803)
at injectInjectorOnly (core.js:940)
at ɵɵinject (core.js:950)
at Object.Overlay_Factory [as factory] (ngx-toastr.js:460)
at R3Injector.hydrate (core.js:17053)
at R3Injector.get (core.js:16803)
at injectInjectorOnly (core.js:940)
at ɵɵinject (core.js:950)
我刚开始倾斜,所以我对此很陌生,不确定自己做错了什么。我查找了几种解决方案,但似乎都没有。
这是我的全局错误处理程序 -
import { ToastService } from './../services/toast.service';
import { ErrorHandler, NgZone, Injectable, Injector } from '@angular/core';
@Injectable({
providedIn: 'root'
})
export class AppErrorHandler extends ErrorHandler {
constructor(private toast: ToastService,
private injector: Injector,
private zone: NgZone) {
super();
}
handleError(error) {
this.zone.run(() =>
this.toast.errorMsg(error, 'Title')
);
}
这是我的 ToastService -
import { Injectable } from '@angular/core';
import { ToastrService } from 'ngx-toastr';
@Injectable({
providedIn: 'root'
})
export class ToastService {
constructor(private toastr:ToastrService) { }
errorMsg(msg, title) {
this.toastr.error(msg, title);
}
//Subsequently success, warning, and info
}
我尝试了几种解决方案,但似乎都没有奏效。我应该怎么办?