0
0
Angularframework~5 mins

Shared modules for reusable components in Angular - Cheat Sheet & Quick Revision

Choose your learning style9 modes available
Recall & Review
beginner
What is the purpose of a shared module in Angular?
A shared module groups reusable components, directives, and pipes so they can be easily imported into other modules, avoiding code duplication.
Click to reveal answer
beginner
How do you make a component reusable across multiple Angular modules?
Declare the component in a shared module and export it. Then import that shared module wherever you want to use the component.
Click to reveal answer
intermediate
Which Angular decorator is used to define a module that can export components?
The @NgModule decorator defines a module. Inside it, the 'exports' array lists components, directives, or pipes to share with other modules.
Click to reveal answer
advanced
Why should you avoid importing a shared module multiple times in Angular?
Importing a shared module multiple times can cause multiple instances of services if provided there. To avoid this, provide services in root or use the forRoot pattern.
Click to reveal answer
beginner
What is a common practice to organize reusable components in Angular projects?
Create a dedicated shared module folder with components, directives, and pipes. Export them from the shared module to keep code clean and maintainable.
Click to reveal answer
What must you do to use a reusable component from a shared module in another module?
ADeclare the component again in the other module
BImport the shared module in the other module
CUse the component selector without importing anything
DExport the component from the other module
Where do you list components to make them reusable in Angular?
AIn the 'exports' array of @NgModule
BIn the 'imports' array
CIn the 'declarations' array only
DIn the 'providers' array
What is a risk of providing services inside a shared module?
AMultiple instances of the service may be created
BServices become global automatically
CServices cannot be injected
DServices will not work in lazy-loaded modules
Which Angular feature helps avoid multiple service instances from shared modules?
ANgModule imports
BLazy loading
CComponent inheritance
DforRoot pattern
What should a shared module NOT usually contain?
AReusable components
BCommon directives and pipes
CFeature-specific services
DExports of reusable items
Explain how to create and use a shared module for reusable components in Angular.
Think about how to group and share components across your app.
You got /4 concepts.
    Describe the potential problem with services in shared modules and how to solve it.
    Consider what happens when a module is imported in many places.
    You got /3 concepts.