将 Angular Cli 升级至 1.3.1 后,现在出现了一些警告信息。
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
每个类都有这样的结构:
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 { }
相比于 app.routing.ts
export const AppRoutes: Routes = [
{
path: 'workSession',
loadChildren: './work-sessions/work-session-list/work-session-list.module#WorkSessionListModule'
}
.
.
.
在 app.module 中
@NgModule({
imports: [
CommonModule,
BrowserAnimationsModule,
FormsModule,
RouterModule.forRoot(AppRoutes),
})
],
declarations: [
AppComponent
]
bootstrap: [AppComponent]
})
export class AppModule {}
我该怎么解决这个问题?它可以工作,但是我有很多警告。
index.ts
文件被称为“barrels”,在Angular2 R.C. 5之前非常有用,因为那时还没有NgModules。在那个时候,“barrels”是避免无数导入/导出的唯一解决方案。现在我们有了模块,它们已经过时了。https://angular.io/guide/glossary#barrel - Alex BeugnetngModule
,在我看来,index.ts 仍然很有用,它可以避免无数的导入。 - Pardeep Jain