CHAPTER 16
Beginner
Angular Modules
Updated: May 18, 2026
5 min read
# CHAPTER 16
Angular Modules
1. Chapter Introduction
An Angular Module (NgModule) is a container that groups related components, directives, pipes, and services together. Every Angular app has at least one module —AppModule. As applications grow, you organize code into Feature Modules (e.g., AdminModule, AuthModule), Shared Modules (for reusable UI), and a Core Module (for singletons). Note: Modern Angular (v17+) increasingly uses Standalone Components that don't require modules, but understanding NgModules is still essential for most existing codebases.
2. Learning Objectives
-
Understand the
@NgModuledecorator and its arrays.
- Create feature modules to organize your application.
- Build a shared module for reusable components.
- Configure lazy-loaded feature modules.
3. The @NgModule Decorator
app.module.ts
4. Feature Modules
A Feature Module groups all code related to one domain area:
bash
products.module.ts
text
5. Shared Module
A Shared Module exports commonly used components and Angular modules to avoid importing them in every feature module:
typescript
Now any Feature Module just imports SharedModule:
typescript
6. Core Module (For Singletons)
The Core Module is imported ONCE inAppModule and contains singleton services and app-wide components like Navbar and Footer:
typescript
7. Lazy Loading Feature Modules
app-routing.module.ts
8. Common Mistakes
-
Declaring a component in two modules: A component can only belong to ONE module's
declarations. If you need it in multiple places, move it to aSharedModuleand export it.
-
Forgetting to export: If you add a component to a module's
declarationsbut don'texportit, other modules that import this module cannot use it.
9. MCQs with Answers
Question 1
What does the declarations array in @NgModule contain?
Question 2
What does the imports array in @NgModule contain?
Question 3
What does the exports array in @NgModule contain?
Question 4
What type of module groups reusable components and Angular modules shared across the app?
Question 5
What is the purpose of the Core Module?
Question 7
In modern Angular (v17+), what replaces the need for NgModules in many cases?
Question 8
What is lazy loading in terms of modules?
Question 9
What is the bootstrap array in AppModule used for?
Question 10
Why must CommonModule (not BrowserModule) be imported in Feature Modules?
10. Interview Questions
-
Q: Explain the difference between
declarations,imports, andexportsin an NgModule.
-
Q: What is the difference between
BrowserModuleandCommonModule?
11. Summary
NgModules are the organizational containers of Angular applications. By separating code into Feature Modules, Shared Modules, and a Core Module, large applications remain manageable. Lazy loading of Feature Modules significantly improves startup performance by deferring code until it is actually needed.12. Next Chapter Recommendation
Components need to talk to each other! In Chapter 17: Component Communication, we will master@Input, @Output, EventEmitter, and service-based communication for parent-child and sibling component interactions.