【发布时间】:2017-03-24 09:04:03
【问题描述】:
我一直在努力将services 相互注入。以下博客Circular Dependency in constructors and Dependency Injection 有点让人困惑
两个对象中的一个隐藏了另一个对象 C
在相互注入服务类时出现以下错误
无法解析 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);
}
}
您的 cmets 和回答将不胜感激。
谢谢
【问题讨论】:
标签: angular dependency-injection circular-dependency