我延迟加载的基本动机是因为我的main.js文件约为10 mb,并且主页加载需要时间。我希望家庭组件js文件的大小应减小。 我是否需要延迟加载除home组件之外的所有其他组件?我错了什么。
在终端中编译成功,但是在控制台中显示空白页面并显示以下错误
Uncaught Error: Component MyHomeComponent is not part of any NgModule or the module has not been imported into your module.
at JitCompiler.push../node_modules/@angular/compiler/fesm5/compiler.js.JitCompiler._createCompiledHostTemplate (compiler.js:26096)
在我的家庭目录内:
import { NgModule } from '@angular/core';
import { Routes, RouterModule } from '@angular/router';
import { MyHomeComponent } from './my-home.component';
const routes: Routes = [
{
path: "", component: MyHomeComponent
}
];
@NgModule({
imports: [RouterModule.forChild(routes)],
exports: [RouterModule]
})
export class MyHomeRoutingModule { }
我的家庭模块:
import { NgModule } from '@angular/core';
import { CommonModule } from '@angular/common';
import { MyHomeRoutingModule } from './my-home-routing.module';
import { MyHomeComponent } from './my-home.component';
@NgModule({
declarations: [MyHomeComponent],
imports: [
CommonModule,
MyHomeRoutingModule
]
})
export class MyHomeModule { }
在主应用模块中,我从声明列表中删除了MyHomeComponent:
@NgModule({
declarations: [
AppComponent,
WhoWeAreComponent,
在主应用程序路由中:
const routes: Routes = [
{
path: '',
loadChildren: "../app/my-home/my-home.module#MyHomeModule"
}