我想在应用程序的多个部分中使用 Angular 组件,包括在延迟加载模块内的组件中。我不知道如何声明在惰性模块中使用它的组件。我将向您展示不同文件的一些相关部分:
应用程序模块.ts
import { FpgTimeComponent } from './fpgTime/fpg-time.component';
@NgModule({
declarations: [
AppComponent,
(...)
FpgTimeComponent
应用程序路由.ts
const appRoutes: Routes = [
{ path: '', redirectTo: 'customer', pathMatch: 'full' },
{
path: 'customer',
component: CustomerComponent
},
{
path: 'lazy',
loadChildren: 'app/lazy/lazy.module#LazyModule'
}
];
惰性模块.ts
import { FpgTimeComponent } from '../fpgTime/fpg-time.component';
import { LazyComponent } from './lazy.component';
import { routing } from './lazy.routing';
@NgModule({
imports: [routing],
declarations: [
LazyComponent,
FpgTimeComponent
]
})
该应用程序加载,但是当我转到惰性路线时,它会抛出以下错误:
未捕获(承诺):错误:类型 FpgTimeComponent 是
2 个模块的声明:AppModule 和 LazyModule!请考虑
将 FpgTimeComponent 移至导入 AppModule 的更高模块并
惰性模块。您还可以创建一个新的 NgModule 来导出和
包含 FpgTimeComponent 然后在 AppModule 中导入该 NgModule 并
惰性模块。
我不会在任何地方导入 LazyModule,因为它是延迟加载的。那么,我如何声明组件 FpgTimeComponent 以便能够在惰性模块(以及非惰性组件)中使用它?
提前致谢,