9
私はservices
をお互いに注入するのに苦労してきました。それは二つのオブジェクトの円の依存性注入角度2
一つは互いに
にサービスクラスを注入しながらは、私は次のエラーを取得する別のオブジェクトCを隠していると言うところ次のブログCircular Dependency in constructors and Dependency Injectionは一種の混乱されます
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);
}
}
あなたのコメントと回答は非常に高く評価されます。
おかげ
'最大コールスタックサイズexceeded' –
を引き起こすサービスのいずれかを注入することにより、循環依存を回避することができます'インジェクターを介して両方のサービスを注入しようとしました –
これは機能しましたか?サイクルを中断するために 'setTimout()'が必要かもしれません(覚えていない)。 –