自定义了一个component, 结果在其他页面引用时报了错:
'xxx' is not a known element.
之前使用自定义的component倒是正常的。排查了代码,发现是非懒加载页面的方式引起的。
以前通过lazyload来加载一个页面时,一般这样:
{ path: 'test', loadChildren: '../x/xx/xxx.module#XXXPageModule' }
// 然后在XXXPageModule中import对应的自定义component或者components.module.ts
// 最后在xxx.page.html中直接可以使用
但现在是非懒加载方式,如:
{ path: 'test2', component: XXXPage }
那就需要在定义import XXXPage
之前就把component给引用进来,比如:
@NgModule({
imports: [
ComponentsModule, // ComponentsModule来自components.module.ts,包含了你自定义的component集合
RouterModule.forChild([
{ path: '', component: HomePage },
{ path: 'test2', component: XXXPage } // XXXPage使用了你自定义的component
])
],
declarations: [XXXPage],
providers: [],
})
export class HomePageModule {
}