L
L
lilwings2020-01-04 06:35:45
Angular
lilwings, 2020-01-04 06:35:45

How does import work in angular and what is the optimization from sharedModule?

In general, I don’t understand how the import works, I have two assumptions:
1) The class logic is copied to where it is imported,
i.e. I import one component (the same) into 10 modules, then this component will be copied 10 times
2) At the first import into a common bundle gets a component (and the like) and then where there is an import, access is simply opened
And how can the SharedModule optimize the application?

Answer the question

In order to leave comments, you need to log in

1 answer(s)
A
Anton Shvets, 2020-01-04
@lilwings

Importing module1 into module2 initializes the module1 injector and makes it available to the module2 injector.
Module1's provider instances are created, and module1's declared entities and new module1's provider instances are made visible to module2.
Components cannot be imported.
The location of the bundles determines the webpack, if there are no lazy modules, then everything will be in main. If there are lazy, then common imports will most likely also fall into main.
Your option 2 is closer to reality.
SharedModule is not needed. It serves as a type aggregator for shared modules so that there are fewer lines in imports.

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question