创建component、module、service...
Run ng generate component component-name
to generate a new component. You can also use ng generate directive|pipe|service|class|guard|interface|enum|module
.
e.g. I will create a new page named "dc data" under the "dc-management" directory which is under the control of the specified module named the same.
Then I will create a new component named "dc list" under this module.
Run like this:
1.cd root directory
2.ng g m pages/dc-management/dc-data --routing
3.ng g c pages/dc-management/dc-data/dc-list
使用loadChildren
惰性加载子模块
创建带routing
的子module
ng g m customers --routing
创建由该子模块管理的页面组件
ng g c customers/customer-list
在app-routing.module
中使用loadChildren
指定子module
const routes: Routes = [
{
path: '/',
component: HomeComponent
},
{
path: 'customers',
loadChildren: './customers/customers.module#CustomersModule'
},
{
path: 'orders',
loadChildren: './orders/orders.module#OrdersModule'
},
{
path: '',
redirectTo: '',
pathMatch: 'full'
}
];
在customer-routing.module
中创建子路由
const routes: Routes = [
{
path: '',
component: CustomerListComponent
}
];
@NgModule({
imports: [RouterModule.forChild(routes)],
exports: [RouterModule]
})
网友评论