But the URL is /product with no id parameter. What issue will occur?
medium
A. this.id will be null, no error occurs
B. Runtime error because 'id' parameter is missing
C. Subscription will not trigger at all
D. this.id will be undefined and cause template error
Solution
Step 1: Understand paramMap.get behavior when param missing
If the parameter does not exist, paramMap.get() returns null, not an error.
Step 2: Check subscription behavior
The subscription still triggers with the current paramMap, so this.id becomes null.
Final Answer:
this.id will be null, no error occurs -> Option A
Quick Check:
Missing param returns null, no error [OK]
Hint: Missing param returns null, not error [OK]
Common Mistakes:
Expecting runtime error if param missing
Thinking subscription won't trigger
Confusing undefined with null
5. You want to create a component that updates its displayed data whenever the route parameter postId changes without recreating the component. Which approach correctly handles this using ActivatedRoute?
hard
A. Read postId once in the constructor and store it
B. Reload the entire component manually on route change
C. Use snapshot.paramMap.get('postId') only in ngOnInit
D. Subscribe to paramMap in ngOnInit and update data inside the subscription callback
Solution
Step 1: Understand component reuse on route param change
Angular reuses the component instance when only route parameters change, so ngOnInit runs once.
Step 2: Use paramMap subscription to detect param changes
Subscribing to paramMap lets you react to parameter changes dynamically without recreating the component.
Step 3: Why snapshot is insufficient
snapshot.paramMap reads parameters only once and won't update if params change while component is active.
Final Answer:
Subscribe to paramMap in ngOnInit and update data inside the subscription callback -> Option D
Quick Check:
Subscribe paramMap for dynamic param changes [OK]
Hint: Subscribe to paramMap to handle param changes live [OK]
Common Mistakes:
Using snapshot only and missing param updates
Reading param once in constructor
Manually reloading component instead of subscribing
Recommended
Ready to prove it?
Pass the test and this pattern moves unknownstrongwhile earning +1 Grip toward your certificate.