Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Angular 4 Circular dependency detected

Upgrading Angular Cli to 1.3.1 I have some warnings now

WARNING in Circular dependency detected: src\app\work-sessions\work-session-list\work-session-list.routing.ts -> src\app\work-sessions\work-session-list\index.ts -> src\app\work -sessions\work-session-list\work-session-list.routing.ts 

Every class have a structure like this:

enter image description here

work-session-list.routing.ts

import { Route } from '@angular/router'; import { WorkSessionListComponent } from './index';  export const WorkSessionRoutes: Route[] = [   {     path: '',     component: WorkSessionListComponent   }, ]; 

Index.ts

export * from './work-session-list.component'; export * from './work-session-list.routing'; 

work-sessions-list.module.ts

import { WorkSessionListComponent } from './work-session-list.component'; import { WorkSessionRoutes } from './work-session-list.routing'; import { DataTableModule } from 'primeng/primeng'; import { CommonModule } from '@angular/common'; import { NgModule } from '@angular/core'; import { FormsModule } from '@angular/forms'; import { RouterModule } from '@angular/router';  @NgModule( {     imports: [RouterModule.forChild( WorkSessionRoutes ), CommonModule , FormsModule],      declarations: [WorkSessionListComponent],     exports: [WorkSessionListComponent] } )  export class WorkSessionListModule { } 

Than in app.routing.ts

export const AppRoutes: Routes = [       {         path: 'workSession',         loadChildren: './work-sessions/work-session-list/work-session-list.module#WorkSessionListModule'       } . . . 

And in app.module

 @NgModule({ imports: [ CommonModule, BrowserAnimationsModule, FormsModule, RouterModule.forRoot(AppRoutes),  })   ],   declarations: [     AppComponent   ]   bootstrap: [AppComponent] }) export class AppModule {} 

How can I solve this? It works but I have a lot of warnings

like image 326
Alessandro Celeghin Avatar asked Sep 08 '17 09:09

Alessandro Celeghin


People also ask

What is circular dependency warning?

A cyclic dependency exists when a dependency of a service directly or indirectly depends on the service itself. For example, if UserService depends on EmployeeService , which also depends on UserService . Angular will have to instantiate EmployeeService to create UserService , which depends on UserService , itself.

What does circular dependency mean in Google Sheets?

When you see the circular dependency detected error displayed in your Google spreadsheet, this means that your formula is referring to a range that contains the formula itself, or in other words when the formula input, is dependent on the output.


1 Answers

As the warning says, work-session-list.routing.ts depends on index.ts:

import { WorkSessionListComponent } from './index'; 

And index.ts depends on work-session-list.routing.ts:

export * from './work-session-list.routing'; 

The first dependency is not necessary, since you could import WorkSessionListComponent directly from its source file:

import { WorkSessionListComponent } from './work-session-list.component'; 

This change should fix the problem.

like image 161
Ján Halaša Avatar answered Sep 16 '22 15:09

Ján Halaša