I have went through the below SO Question for a solution:
Angular: 7.2.1 ES6 class ReferenceError : Cannot access 'X' before initialization
Firstly, I'm getting the below warnings on my VS Code terminal:
WARNING in Circular dependency detected: src\app\modules\asset-classes\fixed-income\fixed-deposits\components\fixed-deposits-details\fixed-deposits-details.component.ts -> src\app\modules\asset-classes\fixed-income\fixed-deposits\components\fixed-deposits-form\fixed-deposits-form.component.ts -> src\app\modules\asset-classes\fixed-income\fixed-deposits\components\fixed-deposits-details\fixed-deposits-details.component.ts
WARNING in Circular dependency detected: src\app\modules\asset-classes\fixed-income\fixed-deposits\components\fixed-deposits-form\fixed-deposits-form.component.ts -> src\app\modules\asset-classes\fixed-income\fixed-deposits\components\fixed-deposits-details\fixed-deposits-details.component.ts -> src\app\modules\asset-classes\fixed-income\fixed-deposits\components\fixed-deposits-form\fixed-deposits-form.component.ts
WARNING in Circular dependency detected: src\app\modules\shared\components\common-dialog\common-dialog.component.ts -> src\app\view-manager.service.ts -> src\app\modules\shared\components\common-dialog\common-dialog.component.ts
WARNING in Circular dependency detected: src\app\view-manager.service.ts -> src\app\modules\shared\components\common-dialog\common-dialog.component.ts -> src\app\view-manager.service.ts
Now, that obviously because of the below code in my respective components:
fixed-deposits-form.component.ts
On Save click >>
this.viewService.loadSideNavWithCallback(
FixedDepositsDetailsComponent,
(compRef: ComponentRef<any>) => {
compRef.instance.fixedDeposit = fixedDepositEntity;
});
fixed-deposits-details.component.ts
On Edit click >>
this.viewService.loadSideNavWithCallback(
FixedDepositsFormComponent,
(compRef: ComponentRef<any>) => {
compRef.instance.fixedDeposit = this.fixedDeposit;
});
The viewService is basically my ViewManagerService that helps achieved loose coupling between angular components and also serves for view navigation. Since the FixedDepositsFormsComponent & FixedDepositsDetailsComponent open in a side-nav (which is present on the AppComponent), the ViewManagerService does the job of load those components.
Although it is pretty obvious that I have a circular dependency, I don't know how to fix it.
Also I'm getting the below error in my browser console:
Uncaught ReferenceError: Cannot access 'FixedDeposit' before initialization at Module.FixedDeposit (main.js:4274) at Module../src/app/modules/asset-classes/fixed-income/fixed-deposits/components/fixed-deposits-details/fixed-deposits-details.component.ts (fixed-deposits-details.component.ts:21)
Now the line no.21 simply points to my @Input property on the details component:
export class FixedDepositsDetailsComponent implements OnInit {
@Input() fixedDeposit: FixedDeposit;
If I remove the loadSideNavWithCallback code (called on save click) from my FixedDepositsFormComponent, there's no error. But I cannot do away with it since I need to have that code to load the details component.
Appreciate any help in advance.