Bird
0
0

Identify the error in this shared module setup:

medium📝 Debug Q14 of 15
Angular - Modules
Identify the error in this shared module setup:
@NgModule({
  declarations: [SharedCardComponent],
  imports: [CommonModule]
})
export class SharedModule {}
@NgModule({
  imports: [SharedModule],
  declarations: [DashboardComponent]
})
export class DashboardModule {}
DashboardComponent template uses <app-shared-card> but Angular throws an error.
ACommonModule should not be imported in SharedModule
BDashboardComponent should import SharedCardComponent directly
CDashboardModule should declare SharedCardComponent again
DSharedCardComponent is not exported from SharedModule
Step-by-Step Solution
Solution:
  1. Step 1: Check SharedModule exports

    SharedCardComponent is declared but not exported, so other modules can't use it.
  2. Step 2: Understand Angular module sharing rules

    To use a component from another module, it must be exported by that module.
  3. Final Answer:

    SharedCardComponent is not exported from SharedModule -> Option D
  4. Quick Check:

    Declare + export needed to share component [OK]
Quick Trick: Always export components to share them outside module [OK]
Common Mistakes:
  • Forgetting to export declared components
  • Trying to redeclare components in feature modules
  • Misunderstanding imports vs exports

Want More Practice?

15+ quiz questions · All difficulty levels · Free

Free Signup - Practice All Questions
More Angular Quizzes