0
0
Angularframework~20 mins

Shared modules for reusable components in Angular - Practice Problems & Coding Challenges

Choose your learning style9 modes available
Challenge - 5 Problems
🎖️
Angular Shared Modules Master
Get all challenges correct to earn this badge!
Test your skills under time pressure!
component_behavior
intermediate
2:00remaining
How does a shared module affect component reuse?
In Angular, you create a shared module that exports a button component. What happens when you import this shared module into two different feature modules and use the button component in both?
AYou must declare the button component again in each feature module for it to work.
BAngular throws an error because the button component is declared in multiple modules.
CThe button component only works in the first feature module that imports the shared module.
DThe button component is available in both feature modules and renders correctly without duplication issues.
Attempts:
2 left
💡 Hint
Think about how Angular handles declarations and exports in shared modules.
📝 Syntax
intermediate
2:00remaining
Identify the correct way to export components in a shared module
Which of the following Angular shared module code snippets correctly exports a reusable component named MyButtonComponent?
Aimports: [CommonModule], declarations: [MyButtonComponent], exports: [MyButtonComponent]
Bimports: [CommonModule], declarations: [], exports: [MyButtonComponent]
Cimports: [CommonModule], declarations: [MyButtonComponent], exports: []
Dimports: [], declarations: [MyButtonComponent], exports: [MyButtonComponent]
Attempts:
2 left
💡 Hint
Remember that a component must be declared before it can be exported.
🔧 Debug
advanced
2:00remaining
Why does importing a shared module cause a 'component is not a known element' error?
You created a shared module exporting MyCardComponent. You imported the shared module into a feature module but get an error: 'my-card' is not a known element. What is the most likely cause?
AThe shared module does not export <code>MyCardComponent</code> in its exports array.
BThe <code>MyCardComponent</code> is declared in the feature module instead of the shared module.
CThe feature module forgot to import <code>CommonModule</code>.
DAngular requires components to be declared in every module where they are used.
Attempts:
2 left
💡 Hint
Check if the component is both declared and exported in the shared module.
lifecycle
advanced
2:00remaining
How does Angular handle service instances in shared modules?
You provide a service in a shared module and import this module into multiple feature modules. How many instances of the service will Angular create at runtime?
AOne single instance shared across all modules importing the shared module.
BOne instance per feature module that imports the shared module.
CA new instance every time the service is injected in a component.
DNo instances are created unless the service is provided in the root injector.
Attempts:
2 left
💡 Hint
Consider where the service is provided and how Angular injectors work.
🧠 Conceptual
expert
3:00remaining
Best practice for organizing reusable components and services in Angular
You want to create a shared module for reusable UI components and services used across many feature modules. Which approach follows Angular best practices for shared modules?
ACreate one shared module that declares and exports all components and provides all services.
BDeclare components and provide services directly in each feature module to avoid shared module complexity.
CCreate separate shared modules: one for components (exported) and one for services (providedIn root), then import only needed modules.
DProvide services in shared modules and import these modules multiple times to get fresh instances.
Attempts:
2 left
💡 Hint
Think about separation of concerns and service instance management.