How to correctly import the Angular Material module through a shared module in Angular 4?

后端 未结 4 1118
灰色年华
灰色年华 2021-01-18 06:42

I\'m building an application using Angular paired with Angular Material, and I\'m having some issues with my modules structure.

As the guidelines suggest, importing

4条回答
  •  星月不相逢
    2021-01-18 06:47

    Depending on your compiling and deployment strategy you'll want to use tree shaking (for dead-code elimination or live-code import). This is the main motivation for MaterialModule being deprecated. The official suggestion is to only import the components you need in the modules that need it. Your solution of creating a single MaterialModule with all the imports is undoing that aspect but might work depending on your project structure (if you're only using a single module for example).

    Try removing MaterialModule from your SharedModule exports. That way you only have a single point of entry for the module in your app root.

提交回复
热议问题