我正在开发一个大型应用程序Angular 2
and ASP.net
MVC。
我的应用程序中有大约 120 个组件,它们都在 @ngModule 声明块中声明:
@NgModule({
imports: [CommonModule],
declarations: [Component1, Component2, Component3, ..., Component120]
})
有没有一种机制可以缩短这个时间?
您可以构建一个共享模块并将组件添加到该模块中,然后您只需将共享模块添加到imports: [MySharedModule]
以及导出的所有组件和指令MySharedModule
可供导入模块使用。
@NgModule({
imports: [ CommonModule ],
declarations: [ Component1, Component2, Component3.... Component120
],
exports: [ Component1, Component2, Component3.... Component120 ],
})
导出类 MySharedModule {}
@NgModule({
declarations: [AppComponent],
bootstrap: [AppComponent],
imports: [BrowserModule, MySharedModule]
})
class AppModule {}
本文内容由网友自发贡献,版权归原作者所有,本站不承担相应法律责任。如您发现有涉嫌抄袭侵权的内容,请联系:hwhale#tublm.com(使用前将#替换为@)