To enable Lazy Loading and CodeSplitting techniques in Angular you have to build your applications in a modular way.
What are the modules in Angular
By default, Angular has only one module in the app.module.ts
file. All your components, services, pipe, etc. are imported here. It uses a decorator called @ngModule()
that looks similar to the following:
@NgModule({ imports: [], declarations: [], exports: [], providers: [], bootstrap: [] })export class AppModule { }
When modularizing an application, each module will have its own unique components, services or the files it will need.
Types of Modules in Angular
We can identify several types of modules. The AppModule is the root module that starts your application. There are Routing Modules for defining routes.
The Shared Module that has services or components shared by the whole application. The Feature/Domain Module that are modules specific to your application.
In this way, Angular builds an ecosystem of modules, being able to divide an APP into N parts to optimize performance and maintain an order in the source code to make it understandable and scalable.
Contributed by: Kevin Fiorentino.
Want to see more contributions, questions and answers from the community?