gpt4 book ai didi

forms - Angular 2 : Too many components in a module?

转载 作者:行者123 更新时间:2023-12-02 04:38:01 25 4
gpt4 key购买 nike

我目前正在制作一个注册表单,它有多个步骤和各种条件表单,具体取决于帐户类型。该模块有近 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
}

最佳答案

模块中的组件编号仅与首次加载时间(或页面刷新)有关,然后将它们加载到内存中。在其他地方寻找问题

关于forms - Angular 2 : Too many components in a module?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/40296893/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com