Skip to main content
Saram Consulting LLC

Angular

Here's why your Angular project might not contain an app.module.ts file and what to do about it:

1. Standalone Components (Angular 14 and onwards)

2. Angular CLI with the --no-standalone Flag

3. Older Angular Projects Upgraded to v14+

How to Tell if Standalone Components Are in Use

Check your main app.component.ts file:

What to Do

You bring up a great point! Let me clarify the interplay between Angular Material and the app.module.ts:

The Shift with Standalone Components

How to Work with Angular Material + Standalone Components

  1. Direct Import: With standalone components, you'll import the Angular Material modules directly into the specific components where you use them. For example, if you want to use a Material button in your my-component.ts file:

    import { MatButtonModule } from '@angular/material/button';
    
    @Component({
      standalone: true,
      imports: [MatButtonModule], 
      // ... rest of your component
    })
    export class MyComponent { ... }
  2. Shared Material Module (Optional): For larger projects where you use Angular Material extensively, you might still find it convenient to create a separate module to bundle commonly used Material modules together. This module can then be selectively imported into other standalone components.

Example: material.module.ts

import { NgModule } from '@angular/core';
import { MatButtonModule } from '@angular/material/button';
import { MatToolbarModule } from '@angular/material/toolbar';
import { MatIconModule } from '@angular/material/icon';
// ... other required Material imports

@NgModule({
  imports: [
    MatButtonModule,
    MatToolbarModule,
    MatIconModule
    // ...
  ],
  exports: [
    MatButtonModule,
    MatToolbarModule,
    MatIconModule
    // ...
  ]
})
export class MaterialModule { }

Important Note: Even with standalone components, there are some situations where you might still need a traditional app.module.ts:

Let me know if you'd like a more detailed example of configuring Angular Material in a project using standalone components!