我试图通过创建另一个路由模块并导入延迟加载组件来实现延迟加载,但我仍然收到以下错误。有人能解释我哪里出错了吗?
这是我的代码 的 setup.module.ts
import {NgModule} from '@angular/core';
import {CommonModule} from '@angular/common';
import {SetupRoutingModule} from './setup-routing.module';
import {DevicesComponent} from './devices/devices.component';
import {StoresComponent} from './stores/stores.component';
import {MaterialModule} from '../../shared/material.module';
import {FormsModule} from '@angular/forms';
@NgModule({
imports: [
CommonModule,
SetupRoutingModule,
MaterialModule,
FormsModule
],
declarations: [ DevicesComponent, StoresComponent],
})
export class SetupModule { }
App.module.ts
import {SetupRoutingModule} from './components/setup/setup-routing.module';
const routes: Routes = [
{path: '', component: DashboardComponent},
{path: 'setup', loadChildren: 'app/components/setup/setup.module#SetupModule'},
{path: '**', redirectTo: ''}
];
@NgModule({
declarations: [
AppComponent,
NavbarComponent,
PublishComponent,
DashboardComponent,
],
imports: [
BrowserModule,
BrowserAnimationsModule,
MaterialModule,
FlexLayoutModule,
FormsModule,
SetupRoutingModule,
ContentRoutingModule,
RouterModule.forRoot(routes)
],
providers: [],
bootstrap: [AppComponent]
})
export class AppModule { }
答案 0 :(得分:2)
在导入 SetupModule
下导入 app.module.ts
imports: [
BrowserModule,
BrowserAnimationsModule,
MaterialModule,
FlexLayoutModule,
FormsModule,
SetupRoutingModule,
ContentRoutingModule,
SetupModule,
RouterModule.forRoot(routes)
]