Bird
0
0

Given this Angular module code, what will be the output if you try to use SharedComponent in a component declared in FeatureModule?

medium📝 Predict Output Q4 of 15
Angular - Modules
Given this Angular module code, what will be the output if you try to use SharedComponent in a component declared in FeatureModule?
@NgModule({
  declarations: [SharedComponent],
  exports: [SharedComponent]
})
export class SharedModule {}

@NgModule({
  declarations: [FeatureComponent],
  imports: [SharedModule]
})
export class FeatureModule {}
ASharedComponent must be declared again in FeatureModule
BFeatureComponent can use SharedComponent without errors
CFeatureComponent cannot use SharedComponent; error at compile time
DFeatureModule must bootstrap SharedComponent to use it
Step-by-Step Solution
Solution:
  1. Step 1: Understand module imports and exports

    SharedModule declares and exports SharedComponent. FeatureModule imports SharedModule, so it gains access to exported components.
  2. Step 2: Confirm usage in FeatureComponent

    Because SharedComponent is exported and SharedModule is imported, FeatureComponent can use SharedComponent without errors.
  3. Final Answer:

    FeatureComponent can use SharedComponent without errors -> Option B
  4. Quick Check:

    exports + imports = shared components usable [OK]
Quick Trick: Exported components become usable in importing modules [OK]
Common Mistakes:
  • Forgetting to export SharedComponent
  • Not importing SharedModule in FeatureModule
  • Trying to redeclare SharedComponent

Want More Practice?

15+ quiz questions · All difficulty levels · Free

Free Signup - Practice All Questions
More Angular Quizzes