I want to use an Angular component in several parts of my application, including in a component inside a lazy loaded module. I don't know how to declare the component for using it in the lazy module. I'll show you some of the relevant parts of the different files:
app.module.ts
import { FpgTimeComponent } from './fpgTime/fpg-time.component';
@NgModule({
declarations: [
AppComponent,
(...)
FpgTimeComponent
app.routing.ts
const appRoutes: Routes = [
{ path: '', redirectTo: 'customer', pathMatch: 'full' },
{
path: 'customer',
component: CustomerComponent
},
{
path: 'lazy',
loadChildren: 'app/lazy/lazy.module#LazyModule'
}
];
lazy.module.ts
import { FpgTimeComponent } from '../fpgTime/fpg-time.component';
import { LazyComponent } from './lazy.component';
import { routing } from './lazy.routing';
@NgModule({
imports: [routing],
declarations: [
LazyComponent,
FpgTimeComponent
]
})
The app loads, but when I go to the lazy route, it throws the following error:
Uncaught (in promise): Error: Type FpgTimeComponent is part of the declarations of 2 modules: AppModule and LazyModule! Please consider moving FpgTimeComponent to a higher module that imports AppModule and LazyModule. You can also create a new NgModule that exports and includes FpgTimeComponent then import that NgModule in AppModule and LazyModule.
I'm not importing LazyModule anywhere, as it's being lazy loaded. So, how could I declare the component FpgTimeComponent to be able to use it inside the lazy module (and also in non-lazy components)?
Thanks in advance,