我正在尝试实现ConfigService以检索项目中正确环境的正确配置.我目前正在遇到循环依赖
(index):28 Error: (SystemJS) Provider parse errors:
Cannot instantiate cyclic dependency! Http: in NgModule AppModule
Error: Provider parse errors:
Run Code Online (Sandbox Code Playgroud)
在我看来,我已经探索过代码并且存在问题:
CustomHttp
constructor(backend: XHRBackend, options: RequestOptions, public spinnerService: SpinnerService, public exceptionService: ExceptionService, public configService: ConfigService)
Run Code Online (Sandbox Code Playgroud)
ExceptionService
constructor(private _notificationService: NotificationService, private _spinnerService: SpinnerService, private _configService: ConfigService, private _router: Router)
Run Code Online (Sandbox Code Playgroud)
的ConfigService
constructor(private http: Http) {}
Run Code Online (Sandbox Code Playgroud)
如您所见,我在此图中说明了一个循环依赖(没有任何好的约定):
我现在的问题是,如何修复它?我听说过,Injector但我不确定我是否真的可以在这种情况下使用它.
提前感谢您的回答.
我一直在努力services互相注入.构造函数和依赖注入中的以下博客循环依赖关系在它所说的地方有点令人困惑
两个对象之一是隐藏另一个对象C.
我在将Service类注入彼此时遇到以下错误
无法解析PayrollService的所有参数:(SiteService,StorageService,SweetAlertService,?)
//abstractmodal.service.ts
@Injectable()
export abstract class AbstractModel {
abstract collection = [];
constructor(private siteService: SiteService, private storageService: StorageService,
private sweetalertService: SweetAlertService) {}
setCollectionEmpty() {
this.collection = [];
}
}
//account-payable.service.ts
@Injectable()
export class AccountPayableService extends AbstractModel {
public collection = [];
constructor(private sS: SiteService,private stS: StorageService, private sws: SweetAlertService,
private accpPoService: PayablePurchaseOrderService, private attachmentService: AttachmentService,
private injectorService: InjectorService) {
super(sS, stS, sws);
}
}
//injector.service.ts
@Injectable()
export class InjectorService {
constructor(private …Run Code Online (Sandbox Code Playgroud)