Bird
0
0

What will be logged to the console when this Angular code runs?

medium📝 component behavior Q13 of 15
Angular - HTTP Client
What will be logged to the console when this Angular code runs?
this.http.post('https://api.example.com/items', {name: 'Book'}).subscribe(response => console.log(response));
AThe URL string 'https://api.example.com/items'
BAn error because POST requests need no data
CThe server's response object after adding the item
DNothing, because subscribe() is missing
Step-by-Step Solution
Solution:
  1. Step 1: Understand HttpClient.post behavior

    It sends data and waits for the server's response asynchronously.
  2. Step 2: Analyze subscribe callback

    The response from the server is passed to the callback and logged.
  3. Final Answer:

    The server's response object after adding the item -> Option C
  4. Quick Check:

    subscribe logs server response [OK]
Quick Trick: subscribe() logs server response from POST [OK]
Common Mistakes:
MISTAKES
  • Thinking POST requests don't need data
  • Forgetting subscribe() to handle response
  • Expecting URL string to be logged

Want More Practice?

15+ quiz questions · All difficulty levels · Free

Free Signup - Practice All Questions
More Angular Quizzes