Bird
0
0

Which of the following is the correct way to subscribe to route parameters using ActivatedRoute?

easy📝 Syntax Q12 of 15
Angular - Routing
Which of the following is the correct way to subscribe to route parameters using ActivatedRoute?
Athis.route.param.subscribe(params => { const id = params['id']; });
Bthis.route.params.get('id').subscribe(id => { });
Cthis.route.paramMap.subscribe(params => { const id = params.get('id'); });
Dthis.route.getParam('id').subscribe(id => { });
Step-by-Step Solution
Solution:
  1. Step 1: Identify correct ActivatedRoute property

    The correct property to get parameters as an observable is paramMap, not params or others.
  2. Step 2: Use the correct method to get parameter

    From paramMap, use get('id') to retrieve the parameter value.
  3. Final Answer:

    this.route.paramMap.subscribe(params => { const id = params.get('id'); }); -> Option C
  4. Quick Check:

    paramMap + get() = correct subscription [OK]
Quick Trick: Use paramMap.subscribe and get('paramName') [OK]
Common Mistakes:
MISTAKES
  • Using this.route.params.get instead of paramMap
  • Trying to subscribe directly on params.get()
  • Using non-existent getParam method

Want More Practice?

15+ quiz questions · All difficulty levels · Free

Free Signup - Practice All Questions
More Angular Quizzes