Here's a question that might sound silly:
In my Angular project, I am looking to reorganize my component declarations by moving them from angular.module.ts to modules/modules.modules.ts.
The goal is to structure my src/app directory as follows:
src/
app/
. modules/
. . about/...
. . banner/...
. . contact/...
. . portfolio/...
. . services/...
. . testimonial/...
. . modules.module.ts
. app-routing.module.ts
. app.component.html
. app.component.scss
. app.component.spec.ts
. app.component.ts
. app.module.ts
Essentially, I want to consolidate all my component declarations into modules/modules.module.ts
Below is my current approach:
import { NgModule } from '@angular/core';
import { CommonModule } from '@angular/common';
// Modules Components
import { BannerComponent } from './banner/banner.component';
import { ServicesComponent } from './services/services.component';
import { PortfolioComponent } from './portfolio/portfolio.component';
import { TestimonialComponent } from './testimonial/testimonial.component';
import { AboutComponent } from './about/about.component';
import { ContactComponent } from './contact/contact.component';
@NgModule({
imports: [CommonModule],
declarations: [
AboutComponent,
BannerComponent,
ContactComponent,
PortfolioComponent,
ServicesComponent,
TestimonialComponent,
],
exports: [
AboutComponent,
BannerComponent,
ContactComponent,
PortfolioComponent,
ServicesComponent,
TestimonialComponent,
],
})
export class ModulesModule {}
app.module.ts:
// Angular CLI
import { BrowserModule } from '@angular/platform-browser';
import { NgModule } from '@angular/core';
// App Component
import { AppRoutingModule } from './app-routing.module';
import { AppComponent } from './app.component';
// Pages Components
import { HomePageComponent } from './pages/home-page/home-page.component';
import { AboutPageComponent } from './pages/about-page/about-page.component';
import { ServicesPageComponent } from './pages/services-page/services-page.component';
import { PortfolioPageComponent } from './pages/portfolio-page/portfolio-page.component';
import { PortfolioSinglePageComponent } from './pages/portfolio-single-page/portfolio-single-page.component';
import { ContactPageComponent } from './pages/contact-page/contact-page.component';
// Modules Components
//import { BannerComponent } from './modules/banner/banner.component';
//import { ServicesComponent } from './modules/services/services.component';
//import { PortfolioComponent } from './modules/portfolio/portfolio.component';
//import { TestimonialComponent } from './modules/testimonial/testimonial.component';
//import { AboutComponent } from './modules/about/about.component';
//import { ContactComponent } from './modules/contact/contact.component';
import { ModulesModule } from './modules/modules.module';
// Angular Material
import { BrowserAnimationsModule } from '@angular/platform-browser/animations';
import { MaterialModule } from './material/material.module';
// Third Party
import { OwlModule } from 'ngx-owl-carousel';
import { NgxSpinnerModule } from 'ngx-spinner';
// PWA
import { ServiceWorkerModule } from '@angular/service-worker';
// Environment
import { environment } from '../environments/environment';
// Firebase
import { AngularFireModule } from '@angular/fire';
import { AngularFireDatabaseModule } from '@angular/fire/database';
@NgModule({
declarations: [
AppComponent,
HomePageComponent,
AboutPageComponent,
ServicesPageComponent,
ContactPageComponent,
PortfolioPageComponent,
PortfolioSinglePageComponent,
],
imports: [
BrowserModule,
AppRoutingModule,
ModulesModule, // here
BrowserAnimationsModule,
MaterialModule,
OwlModule,
NgxSpinnerModule,
ServiceWorkerModule.register('ngsw-worker.js', {
enabled: true, //environment.production,
}),
AngularFireModule.initializeApp(environment.firebaseConfig),
AngularFireDatabaseModule,
],
providers: [],
bootstrap: [AppComponent],
})
export class AppModule {}
Please keep in mind that for simplicity, I have changed the names in this example. The code was functioning correctly with the declarations in app.module.ts before.