Answer the question
In order to leave comments, you need to log in
Is there another solution for shearedModule?
Hello. I am writing an application, and I encountered such an unpleasant feature. There are many lazy modules (pages) in which I import the same component, respectively, I get an error that I need to make a sharedModule. But it turns out that, for example, there are 5 pages, and there is a sharedModule, and 2 components are shared between 3 pages, and 1 component is shared between 2 pages, and 1 more component is shared between 5 modules. I mean that I had to create a bunch of shared modules to avoid mistakes, it turns out I have 1 shared module for 1 component. Generally something like this
3 lazy pages
@NgModule({
declarations: [],
imports: [
Shared1Module
]
})
export class Lazy1Module {
}
@NgModule({
imports: [
Shared2Module
]
})
export class Lazy2Module {
}
@NgModule({
imports: [
Shared2Module
],
})
export class Lazy3Module {
}
export class My1Component {
}
export class My2Component {
}
export class My3Component {
}
@NgModule({
declarations: [
My1Component,
My2Component
],
exports: [My1Component, My2Component]
})
export class Shared1Module {
}
@NgModule({
declarations: [
My3Component
],
exports: [My3Component]
})
export class Shared2Module {
}
Answer the question
In order to leave comments, you need to log in
1 component - 1 module, quite a normal solution. Of course they should have the same name, not "Shared2" and stupid components are also in this module.
Frequently used ones can already be collected in Shared, as a rule, it is one per project or section. If it loads several unused modules in the current lazy module, it's okay.
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question