4

In Angular 2+ I’m lazy loading a custom module (section of my app). It lazy loads just fine when i navigate to its route, but it has none of my main module’s theming. Also I’ve found that I have to re-import MatButtonModule in my custom module if I want the matbutton behavior in any components defined in said custom module. This seems like unnecessary bloat.

Do I have to re-import modules that I want to use in my custom module that I’m already importing in the main app module? Do I have to reimport the app theme into the custom module?

seabass
  • 1,030
  • 10
  • 22

1 Answers1

5

Yes, every module has to import it's dependencies from your other modules.

A common way of dealing with this is to create a single "Core" module that imports and re exports everything you need in all your modules (things like the CommonModule, FormsModule, etc.)

https://angular.io/guide/sharing-ngmodules

Maxime Michaud
  • 141
  • 1
  • 3
  • That makes sense. I’ll check that out. Thanks for the reply. One more thing. How would I share my md theme across modules? – seabass Jun 16 '18 at 16:51
  • I don't really know the detail, since I haven't used Angular material outside of small, single module projects, but I'd assume you can bundle everything related to the theming in a single module and export all of it, allowing you to easily import it in your other modules. – Maxime Michaud Jun 16 '18 at 17:58