Skip to main content

Posts

Showing posts with the label Why use multiple NgModules?

Why is it bad if a shared module provides a service to a lazy-loaded module?

Why is it bad if a shared module provides a service to a lazy-loaded module? The lazy loaded scenario causes your app to create a new instance every time, instead of using the singleton. Lazy loading is the best practice of loading expensive resources on-demand. This can greatly reduce the initial startup time for single page web applications (SPA). Instead of downloading all the application code and resources before the app starts, they are fetched just-in-time (JIT) , as needed. The eagerly loaded scenario your app to create a singleton, instead of creates new instance every time. Explore in depths about Lazy loading - https://angular-wbecxz.stackblitz.io/partners

What Are the Purpose of @NgModule?

What Are the Purpose of @NgModule? The NgModule is used to simplify the ways you define and manage the dependencies in your applications and also you can consolidate different components and services into cohesive blocks of functionality. The @NgModule metadata divided into three categories as follows. 1.            Static 2.            Runtime 3.            Composability/Grouping Static  – It is compiler configuration and configured via the declarations array. Runtime  - It is injector configuration and configured via the provider’s array. Composability/Grouping  – Introducing NgModules  together and configured via the imports and exports arrays. The following is an example of specifying a NgModule metadata - @ NgModule ({    // Static, This is the compiler configuration ...

Why use multiple NgModules?

Multiple NgModules  provides some potential benefits. Actually, the modules help you to organize an application into associative blocks of functionality. First one is organizing an application code. If you are  putting around 99 resource files in the default app module and see the happing. And the second one is - It opens the possibility of lazy loading via the router.