0

I have a project which has big scope of circular dependency. To tackle the issue I have created the simple project with circular dependency on purpose to come up with the solution.

I have come accross different solutions like using injections. How to solve the circular dependency

but there is also a solution to export all dependencies from a single file which is given by this article https://medium.com/visual-development/how-to-fix-nasty-circular-dependency-issues-once-and-for-all-in-javascript-typescript-a04c987cf0de

I followed the instructions as followed:

moduleA.ts

import { MODULE_B_NAME } from "./internal";

export const MODULE_A_NAME = 'Module A';

export class ModuleA {

  public static getName(): string {

    return MODULE_B_NAME;

  }

}

modeulB.ts

import { MODULE_A_NAME } from "./internal";

export const MODULE_B_NAME = 'Module B';

export class ModuleB {

  public getName(): string {

    return MODULE_A_NAME;

  }

}

app.component.ts

import { Component } from '@angular/core';
import { ModuleA } from './internal';

@Component({
  selector: 'app-root',
  templateUrl: './app.component.html',
  styleUrls: ['./app.component.css']
})
export class AppComponent {
  title = 'test01';


  getSomething() {

    return ModuleA.getName();
  }



}

internal.ts

export * from './app.component';
export * from './moduleA';
export * from './moduleB';

app.module.ts

import { BrowserModule } from '@angular/platform-browser';
import { NgModule } from '@angular/core';

import { AppComponent } from './internal';

@NgModule({
  declarations: [
    AppComponent
  ],
  imports: [
    BrowserModule
  ],
  providers: [],
  bootstrap: [AppComponent]
})

I followed the steps, still it is given circular dependency warnings. what is it that Im not doing right? enter image description here

Sanam
  • 243
  • 5
  • 15

0 Answers0