我一直在努力解决将服务
注入到彼此中的问题。以下博客“构造函数和依赖注入中的循环依赖关系”有些令人困惑,其中说到:
两个对象之一隐藏了另一个对象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 payrollService: PayrollService) {}
cleanPayrollCollection() {
this.payrollService.setCollectionEmpty();
}
}
//payroll.service.ts
@Injectable()
export class PayrollService extends AbstractModel {
public collection = [];
constructor(private sS: SiteService,private stS: StorageService, private sws: SweetAlertService,
private accpService: AccountPayableService) {
super(sS, stS, sws);
}
}
非常感谢您的评论和回答。
谢谢
Maximum call stack size exceeded
- Basheer KharotiInjector
类?是从@angular/core
吗?我在网上找不到相关信息。 - Mouradif@angular/core
时,它起作用了。 - ShadSterling