我目前正在处理注册表单,该表单具有多个步骤和各种条件表单,具体取决于帐户类型。该模块有近30个组件(子组件和父组件的混合),所有这些组件都被导入到模块文件中。这使得整个Angular 2站点运行速度非常慢,尤其是在导航到注册表单然后导航到另一个路径之后。
模块中是否有太多组件/服务/提供商可能会对网站性能造成负面影响?是否建议将多步注册申请表分解为多个模块?
import { CommonModule } from '@angular/common';
import { RouterModule } from '@angular/router';
import { NgModule } from '@angular/core';
import { ReactiveFormsModule } from '@angular/forms';
... all the other imports of components/service for this module
export const routes = [{
path: '',
component: parentComponent,
canActivate: [AuthGuard],
resolve: {
someData: someDataResolver
},
children: [
{ path: '', redirectTo: '0', pathMatch: 'full' },
{ path: '0',
component: someComponent1,
resolve: {
someData1: someData1Resolver
}
},
... a bunch more children routes/components
{ path: '20',
component: someComponent20,
resolve: {
someData20: someData1Resolver
}
}
]
}]
@NgModule({
declarations: [ ... ],
entryComponents: [ ... ],
imports: [ ... ],
providers: [ ... ],
})
export default class SampleModule {
static routes = routes
}
答案 0 :(得分:0)
模块中的组件编号仅在首次加载时间(或页面刷新)时才重要,然后才将其加载到内存中。在其他地方寻找问题