Search code examples
angularangular-module

Angular import external module into every project module or only app?


I have an Angular app with 10 modules. Each time I install a new external package, I need to import it to every module that uses it. is it meant to work like so or there is a way to import it only once to app module ?


Solution

  • No, You should not be doing that. You can make use of Shared Module. Create a Shared Module in your project and then import all the external modules within the Shared Module. So that you could only import Shared module in all your project modules.

    https://angular.io/docs/ts/latest/guide/ngmodule.html#!#shared-module