Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Circular dependency error in angular 5

Always I'm getting warning that is circular dependency

WARNING in Circular dependency detected:
src\app\auth\logout\logout.component.ts -> src\app\auth\_services\authentication.service.ts -> src\app\app.module.ts -> src\app\app-routing.module.ts ->
src\app\auth\logout\logout.component.ts

WARNING in Circular dependency detected:
src\app\theme\layouts\header-nav\header-nav.component.ts -> src\app\_services\data\emp.service.ts -> src\app\app.module.ts -> src\app\theme\layouts\layout.module.ts -> src\app\theme\layouts\header-nav\header-nav.component.ts

WARNING in Circular dependency detected:
src\app\theme\layouts\layout.module.ts -> src\app\theme\layouts\header-nav\header-nav.component.ts -> src\app\_services\data\emp.service.ts -> src\app\app.module.ts -> src\app\theme\layouts\layout.module.ts

WARNING in Circular dependency detected:
src\app\theme\theme-routing.module.ts -> src\app\auth\_guards\auth.guard.ts -> src\app\auth\_services\user.service.ts -> src\app\app.module.ts -> src\app\theme\theme-routing.module.ts

I used this then it was solved

"build": {
      "showCircularDependencies": false
    },

but how to solve this issue, without using "showCircularDependencies": false

like image 929
Ramana V V K Avatar asked Aug 02 '26 02:08

Ramana V V K


1 Answers

I guess there's just no way around it. You probably would be able to escape this by breaking up one of these services into new a service and carefully include them.

Take a look at Single Responsibility Principle. It's the solid way of evading such issues.

like image 83
htshame Avatar answered Aug 03 '26 14:08

htshame



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!