Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Difference between importing a module in app.module and a component

Tags:

import

angular

Angular 5

What is the difference between importing a module in app.module and importing it in the component that it is to be used in?

More specifically, why should a module have to be a part of node modules, app.module, the import array in app.module and the component, before it can be used?

like image 568
rahs Avatar asked Sep 11 '25 10:09

rahs


1 Answers

An Angular module is there to centralize your imports and dependencies.

Imagine you have 170 components, that all need ToasterComponent.

What seems to be the best suited : write 170 imports to the same component, or one line of import ?

So sure, you can use it directly in the component, but if the dependency is shared and used at other places, consider using a module.