Bird
0
0

Given the code below, what will be the final URL requested?

medium📝 component behavior Q13 of 15
Angular - HTTP Client
Given the code below, what will be the final URL requested?
const params = new HttpParams().set('page', '2').set('sort', 'name');
this.http.get('/api/items', { params }).subscribe();
A/api/items
B/api/items?sort=name&page=2
C/api/items?page=2
D/api/items?page=2&sort=name
Step-by-Step Solution
Solution:
  1. Step 1: Understand HttpParams chaining

    Each set returns a new HttpParams with added param; chaining adds both params.
  2. Step 2: Determine param order

    Params appear in order set: page=2 then sort=name.
  3. Final Answer:

    /api/items?page=2&sort=name -> Option D
  4. Quick Check:

    Params chained = URL with both params in order [OK]
Quick Trick: Chained set() adds params in order to URL [OK]
Common Mistakes:
MISTAKES
  • Assuming only last set param remains
  • Ignoring param order in URL
  • Forgetting to pass params in request options

Want More Practice?

15+ quiz questions · All difficulty levels · Free

Free Signup - Practice All Questions
More Angular Quizzes