我有一个顶级Angular模块,可以延迟加载其他两个模块。所有模块都需要访问从node_modules获得的另一个模块。该库模块将导入BrowserModule
和BrowserAnimationsModule
,因此,我当然会收到错误消息“错误:BrowserModule已加载。”这大概是我的代码:
parent-app-routing.module.ts:
import { Routes, RouterModule } from '@angular/router';
const routes: Routes = [
{
path: '',
loadChildren: () =>
import('../../../lazyLoadedModule/src/app/app.module').then(
mod => mod.lazyLoadedModule
)
},
{
path: '',
redirectTo: '',
pathMatch: 'full',
}
];
@NgModule({
imports: [RouterModule.forRoot(routes)],
exports: [RouterModule]
})
export class AppRoutingModule {}
parent-app.module.ts:
@NgModule({
declarations: [AppComponent],
imports: [
BrowserModule,
BrowserAnimationsModule,
**troubleModule**,
AppRoutingModule,
],
providers: [],
bootstrap: [AppComponent]
})
export class AppModule {}
lazy-loaded-app.module.ts:
const routes: Routes = [
{ path: '', component: AppComponent },
{
path: '**',
redirectTo: ''
}
];
@NgModule({
declarations: [
AppComponent
],
imports: [
CommonModule,
**troubleModule**,
RouterModule.forChild(routes)
],
providers: [],
bootstrap: [AppComponent]
})
export class lazyLoadedModule{}
我尝试将其放在我在两个地方都导入的sharedModule中,但这是行不通的。有没有解决的办法? 感谢您的帮助。