Reputation: 4177
I'm moving my app to lazy loading and I found 2 ways of having components loaded.
One is having X components and just one global components.module (e.g. https://www.9lessons.info/2017/12/ionic-angular-lazy-loading-child-components.html) that we'd need to import on our pages. But what happens if we just want one component?
That's the other way which I saw on some @mhartington's repo. We could have again one .module per component as we have with pages: https://github.com/mhartington/lazyLoad2-components/blob/master/src/components/music-card/music-card.module.ts
Is this second way better than the first one? What's the point of having all component loaded on one page if we're using lazy loading?
Upvotes: 1
Views: 738
Reputation: 39432
What I'm writing below is a short excerpt from Angular's Style Guide and will help you decide which your Lazy Loading Strategy.
The basic idea behind Lazy Loading modules in Angular is to load a module only if it's required. The ideal way of implementing it is to create different modules. Now, there would generally be these types of modules in your Angular App:
Keeping all these points in mind, you should break your Angular App down in this way so that it's clear which modules are Feature Modules and can be lazy loaded.
Upvotes: 3