Bird
0
0

Given this code snippet, what will be logged if the URL is '/products?page=2#details'?

medium📝 component behavior Q4 of 15
Angular - Routing
Given this code snippet, what will be logged if the URL is '/products?page=2#details'?
this.route.queryParams.subscribe(params => console.log(params.page));
this.route.fragment.subscribe(frag => console.log(frag));
A2 and details
Bundefined and details
C2 and undefined
Dundefined and undefined
Step-by-Step Solution
Solution:
  1. Step 1: Extract query parameter value

    URL has query param page=2, so params.page will be '2'.
  2. Step 2: Extract fragment value

    URL fragment is 'details', so frag will be 'details'.
  3. Final Answer:

    2 and details -> Option A
  4. Quick Check:

    Query param and fragment values = A [OK]
Quick Trick: Query params and fragment values come from URL parts [OK]
Common Mistakes:
MISTAKES
  • Expecting numbers instead of strings
  • Confusing queryParams with params
  • Ignoring fragment subscription

Want More Practice?

15+ quiz questions · All difficulty levels · Free

Free Signup - Practice All Questions
More Angular Quizzes