Bird
0
0

Which of the following is the correct way to declare an Angular module using the NgModule decorator?

easy📝 Syntax Q12 of 15
Angular - Modules
Which of the following is the correct way to declare an Angular module using the NgModule decorator?
A@NgModule({ declarations: MyComponent, imports: BrowserModule }) export class MyModule {}
B@NgModule({ components: [MyComponent], imports: [BrowserModule] }) export class MyModule {}
C@NgModule({ declarations: [MyComponent], imports: [BrowserModule] }) export class MyModule {}
D@NgModule({ declarations: [MyComponent], import: [BrowserModule] }) export class MyModule {}
Step-by-Step Solution
Solution:
  1. Step 1: Check correct metadata keys

    The correct keys are declarations and imports, both expecting arrays.
  2. Step 2: Validate syntax and spelling

    @NgModule({ declarations: [MyComponent], imports: [BrowserModule] }) export class MyModule {} uses correct keys and array syntax. Others have wrong keys like components or missing arrays.
  3. Final Answer:

    @NgModule({ declarations: [MyComponent], imports: [BrowserModule] }) export class MyModule {} -> Option C
  4. Quick Check:

    Correct keys and arrays = A [OK]
Quick Trick: Use 'declarations' and 'imports' keys with arrays [OK]
Common Mistakes:
  • Using 'components' instead of 'declarations'
  • Forgetting to wrap in arrays
  • Misspelling 'imports' as 'import'

Want More Practice?

15+ quiz questions · All difficulty levels · Free

Free Signup - Practice All Questions
More Angular Quizzes