在我对Angular的探索中,我发现了两种可能的方式在另一个模块中使用一个模块。在模块中使用另一个模块:导入与在路由中使用loadChildren
(使用angular-express-starter project供参考)
方法1: 声明它的
imports
阵列英寸For example@NgModule({ declarations: [ AppComponent ], imports: [ BrowserModule, SharedModule, FormsModule ] })
方法2: 使用
loadChildren
路由。 For example:export const routes: Route[] = [ { path: '', pathMatch: 'full', redirectTo: 'weather'}, { loadChildren: 'app/dashboard/dashboard.module#DashboardModule', path: 'dashboard' }, { loadChildren: 'app/profile/profile.module#ProfileModule', path: 'profile' }, { loadChildren: 'app/weather/weather.module#WeatherModule', path: 'weather' } ];
什么是这两种方法之间的实际差别?
我们还可以通过loadChildren – yurzui