Bird
0
0

What is wrong with this Angular module code?

medium📝 Debug Q14 of 15
Angular - Modules
What is wrong with this Angular module code?
import { NgModule } from '@angular/core';
import { BrowserModule } from '@angular/platform-browser';
import { MyComponent } from './my.component';

@NgModule({
  declarations: [],
  imports: [BrowserModule, MyComponent],
  exports: [MyComponent]
})
export class AppModule {}
A<code>exports</code> cannot include components
B<code>BrowserModule</code> cannot be imported
C<code>MyComponent</code> should be in providers
D<code>MyComponent</code> should be in declarations, not imports
Step-by-Step Solution
Solution:
  1. Step 1: Identify where components belong

    Components like MyComponent must be listed in declarations, not imports.
  2. Step 2: Check imports and exports usage

    Modules go in imports, components go in declarations. Exporting components is allowed.
  3. Final Answer:

    MyComponent should be in declarations, not imports -> Option D
  4. Quick Check:

    Components belong in declarations [OK]
Quick Trick: Components go in declarations, modules in imports [OK]
Common Mistakes:
  • Putting components inside imports
  • Thinking exports can't include components
  • Confusing providers with declarations

Want More Practice?

15+ quiz questions · All difficulty levels · Free

Free Signup - Practice All Questions
More Angular Quizzes