Bird
0
0

Examine this Angular module code snippet:

medium📝 Debug Q6 of 15
Angular - HTTP Client
Examine this Angular module code snippet:
import { NgModule } from '@angular/core';
import { HttpClientModule } from '@angular/common/http';

@NgModule({
  imports: [HttpClientModule],
  providers: [HttpClientModule]
})
export class AppModule {}

What is the issue with this setup?
AHttpClientModule should not be listed in the providers array
BHttpClientModule must be added to declarations instead of imports
CHttpClientModule import path is incorrect
DHttpClientModule must be imported in every component
Step-by-Step Solution
Solution:
  1. Step 1: Understand module metadata

    Modules go into the imports array; services go into providers.
  2. Step 2: Role of HttpClientModule

    HttpClientModule is an NgModule, not a service provider.
  3. Step 3: Identify the error

    Including HttpClientModule in providers is incorrect and unnecessary.
  4. Final Answer:

    HttpClientModule should not be listed in the providers array -> Option A
  5. Quick Check:

    Modules belong in imports, not providers [OK]
Quick Trick: Only services go in providers, modules go in imports [OK]
Common Mistakes:
MISTAKES
  • Adding modules to providers array
  • Confusing modules with services
  • Duplicating module imports in providers

Want More Practice?

15+ quiz questions · All difficulty levels · Free

Free Signup - Practice All Questions
More Angular Quizzes