【发布时间】:2017-06-23 12:23:40
【问题描述】:
我在 Angular 4.x 应用程序中实现了延迟加载模块。
app.route.ts
const routes: Routes = [
{
path: '',redirectTo:'home',pathMatch:'full'
},
{
path:'home',
children:[
{path:'',redirectTo:'index',pathMatch:'full'},
{path:'index',component:HomeComponent},
{path:'dashboard',component:DashBoardComponent}
]
},
{path:'pages',
loadChildren:'./form/form.module#FormModule'
},
{path:'buttons',component:ButtonsComponent},
{path:'card',component:CardComponent},
{path:'**',component:NotFoundComponent}
];
@NgModule({
imports: [RouterModule.forRoot(routes)],
exports: [RouterModule]
})
export class AppRoutingModule { }
form.routing.ts
const routes: Routes = [
{
path:'',component:FormComponent,children:[
{path:'',redirectTo:'login',pathMatch:'full'},
{
path:'signup',component:RegisterComponent
},
{
path:'login',component:LoginComponent},
]
},
];
export const FormRouting: ModuleWithProviders = RouterModule.forChild(routes);
Form.module.ts
@NgModule({
imports:[
CommonModule,
FormRouting,
],
declarations:[
FormComponent,
LoginComponent,
RegisterComponent
]
})
export class FormModule{}
应用程序在没有延迟加载的情况下工作,但在延迟加载后它会生成模板解析错误:
我在 app.module.ts 中导入了MaterialModule。我该如何解决这个问题?提前致谢。
【问题讨论】:
标签: angular lazy-loading angular2-modules