Marmicode
Blog Post
Younes Jaaidi

Your Angular Module is a SCAM!

by Younes Jaaidi • 
Mar 12, 2019 • 4 minutes
Your Angular Module is a SCAM!

Every time I am about to add a component to an Angular application, I feel like there is a bunch of people arguing in my head.


TL;DR

There’s a to generate Single Component Angular Modules.

yarn add @wishtack/schematics
yarn ng g @wishtack/schematics/scam hello-world

Where It All Started

A while ago, I caught this Pull Request from which shows that the Angular team might make NgModules optional in the future.

It inspired me to experiment a new .

ng-markup

The current problem with this approach is that in addition to involving a new syntax, we will have to wait for optional modules support.

By the way, here’s ’s reaction about my previous post and optional modules:

New Template Syntax - Igor Minar Feedback

In the meantime, we have to consider another way to solve this situation.

NgModule Refactoring Hell

One of the main challenges with NgModule is refactoring.

Given the following cute and tiny little module:

@NgModule({
  declarations: [
    SandwichFormComponent,
    SandwichPreviewComponent
  ],
  imports: [
    MatButtonModule,
    MatCardModule,
    ReactiveFormsModule
  ]
})
export class CuteLittleSandwichModule {}

It is already a challenge to move to another module.

For instance, it is hard to tell if & should be kept, moved, or duplicated to the new module.

yarn add @wishtack/schematics
yarn ng g @wishtack/schematics:scam sandwich/sandwich-preview

app/
  sandwich/
    sandwich-preview/
      sandwich-preview.component.ts|html|...