Lazy loading strategy and providers

Right now, using lazy loading, I am loading all of my providers into app.module.ts, which I think is not the best strategy, because it will not speed up the loading time of my application, especially because I have something like 50 user providers (not judge me;)).

So I ask myself, should I really download them all for my application, or if I should download them only where I use them?

I assume that it would be better to download suppliers only where I really use them.

But in this case, then it is not clear to me how to solve the following construction:

Let's say I have three pages (A, B and C) with their own modules and three providers (1,2 and 3).

A use 1
B use 1, 2, 3
C use 1, 2
  • I assume that since 1 is used throughout the application, I would have to declare it in app.module.ts

  • Since 3 is only used on page B, I think I would have to declare it only in B.module.ts

  • But what about 2? How can I declare it both in B.module.tsand in C.module.tsorder to exchange the same “memory” of the provider (if the provider contains a value, both B and C should see the same object), accordingly, how will I encode this? Just by entering the provider "as usual" and angular do the rest?

Thanks in advance for any help, would really be appreciated

UPDATE

Not sure if I understand angular documentation correctly, but what is the purpose, providers should be loaded for the entire application in width?

Cm

https://angular.io/guide/ngmodule-faq#q-component-scoped-providers

+4
2

: app.module.ts, . angular :

-

, app.module.ts, , .
i.e B.module.ts C.module.ts, B page , C page . .

0

, 2 B C .

edit: .

+1

Source: https://habr.com/ru/post/1687371/


All Articles