Bird
0
0

You want to send a POST request to add a new user with name and email, then update a message on success. Which Angular code snippet correctly does this?

hard🚀 Application Q15 of 15
Angular - HTTP Client
You want to send a POST request to add a new user with name and email, then update a message on success. Which Angular code snippet correctly does this?
Athis.http.post('/api/users', {name: userName, email: userEmail}).subscribe(() => this.message = 'User added');
Bthis.http.post('/api/users', userName, userEmail).subscribe(response => this.message = response);
Cthis.http.post('/api/users').subscribe(response => this.message = 'User added');
Dthis.http.get('/api/users', {name: userName, email: userEmail}).subscribe(() => this.message = 'User added');
Step-by-Step Solution
Solution:
  1. Step 1: Verify POST request parameters

    POST requires URL and a single data object containing user info.
  2. Step 2: Check subscribe callback updates message

    On success, the callback sets the message string correctly.
  3. Final Answer:

    this.http.post('/api/users', {name: userName, email: userEmail}).subscribe(() => this.message = 'User added'); -> Option A
  4. Quick Check:

    post(url, data).subscribe(() => update message) [OK]
Quick Trick: POST needs data object; subscribe updates UI on success [OK]
Common Mistakes:
MISTAKES
  • Passing multiple arguments instead of one data object
  • Using GET instead of POST for sending data
  • Not updating message inside subscribe callback

Want More Practice?

15+ quiz questions · All difficulty levels · Free

Free Signup - Practice All Questions
More Angular Quizzes