Bird
0
0

Why does this shared module cause an error?

medium📝 Debug Q7 of 15
Angular - Modules
Why does this shared module cause an error?

@NgModule({
  declarations: [SharedComponent],
  exports: [SharedComponent],
  imports: [SharedModule]
})
export class SharedModule {}
AExports array cannot include components
BSharedComponent is not declared
CImports array must be empty in shared modules
DIt imports itself, causing a circular dependency
Step-by-Step Solution
Solution:
  1. Step 1: Analyze imports array

    The module imports itself, which creates a circular dependency error.
  2. Step 2: Check declarations and exports

    SharedComponent is declared and exported correctly, so no issue there.
  3. Final Answer:

    It imports itself, causing a circular dependency -> Option D
  4. Quick Check:

    Modules must not import themselves [OK]
Quick Trick: Never import the same module inside itself [OK]
Common Mistakes:
  • Importing the same module inside itself
  • Confusing declarations with imports
  • Misunderstanding exports usage

Want More Practice?

15+ quiz questions · All difficulty levels · Free

Free Signup - Practice All Questions
More Angular Quizzes