Bird
0
0

What is wrong with this import statement in an Angular service?

medium📝 Debug Q7 of 15
Angular - Standalone Components
What is wrong with this import statement in an Angular service?
import { HttpClient } from '@angular/http';
AThe import path is correct but HttpClient is deprecated
BHttpClient should be imported from '@angular/common/http', not '@angular/http'
CHttpClient is a default export and should not use curly braces
DNo error; this import is valid
Step-by-Step Solution
Solution:
  1. Step 1: Identify correct package for HttpClient

    HttpClient belongs to '@angular/common/http', not '@angular/http'.
  2. Step 2: Understand impact of wrong import path

    Using wrong path causes module not found or runtime errors.
  3. Final Answer:

    HttpClient should be imported from '@angular/common/http', not '@angular/http' -> Option B
  4. Quick Check:

    HttpClient import path must be '@angular/common/http' [OK]
Quick Trick: Use '@angular/common/http' for HttpClient imports [OK]
Common Mistakes:
  • Using deprecated or wrong package paths
  • Confusing default and named imports

Want More Practice?

15+ quiz questions · All difficulty levels · Free

Free Signup - Practice All Questions
More Angular Quizzes