Bird
0
0

Identify the error in this Angular module code:

medium📝 Debug Q6 of 15
Angular - Modules
Identify the error in this Angular module code:
@NgModule({
  declarations: [MyComponent],
  imports: [BrowserModule],
  providers: [MyComponent]
})
export class AppModule {}
AMyComponent should not be listed in providers
BBrowserModule should be in declarations
CMyComponent must be in exports instead of declarations
Dproviders array cannot be used in NgModule
Step-by-Step Solution
Solution:
  1. Step 1: Understand providers usage

    The providers array is for services, not components.
  2. Step 2: Check component placement

    Components belong in declarations, not providers. Listing a component in providers causes errors.
  3. Final Answer:

    MyComponent should not be listed in providers -> Option A
  4. Quick Check:

    Components go in declarations, services in providers [OK]
Quick Trick: Only services go in providers, not components [OK]
Common Mistakes:
  • Putting components in providers
  • Confusing BrowserModule as a component
  • Thinking providers is optional

Want More Practice?

15+ quiz questions · All difficulty levels · Free

Free Signup - Practice All Questions
More Angular Quizzes