Reputation: 2753
I was trying to refactor my angular source into multiple feature modules. Earlier the source had only one module and all the components were declared inside that single module. For refactoring, I did following steps:
Created a feature module
Moved a component from app module to feature module. Added the component in feature module in declarations list and exports list.
Removed the references of the moved component from app module
Imported feature module into app module.
The source code compiles, but the site does not load. On the console, I could see it crashes because the component in feature module, on its html has used a component from app module.
I thought there is no extra step required to use a component from app module in a feature module. Am I missing something?
Added: Below HTML is from the moved component(component that I moved from app module to feature module), which is using app-organization-user-search component declared in app module.
<div class="col-md-12 full-width py-2">
<app-organization-user-search (addClicked)="addParticipant($event)" (cancelClicked)="addingParticipants = false"></app-organization-user-search>
Added: To all those who are searching answer to the specific problem, the solution is in the comments of the accepted answer.
Upvotes: 2
Views: 1120
Reputation: 3455
For splitting one module into multiple ones, you should mind to export and import all modules and components correctly:
app.module.ts *the „root“ module
@NgModule({
declarations: [
AppComponent,
],
imports: [
// angular
BrowserModule,
HttpClientModule,
// splitted modules
DiversityMattersModule,
PreventingAirPolutionModule,
PeacfullyRevolutionModule,
// ...
],
providers: [],
bootstrap: [AppComponent]
})
export class AppModule {
}
diversity-matters.module.ts Example module from list above
@NgModule({
imports: [
// ...
],
declarations: [
AwesomeComponent,
// ...
],
exports: [
AwesomeComponent,
// ...
],
})
Every component that depends on AppComponent
is now allowed to import AwesomeComponent
.
Upvotes: 1