Bird
0
0

How can you configure Angular routes to pre-fetch multiple data sources using Resolvers before activating a route?

hard📝 Conceptual Q8 of 15
Angular - Advanced Patterns
How can you configure Angular routes to pre-fetch multiple data sources using Resolvers before activating a route?
AChain multiple Resolvers inside a single Resolver service and assign it to the route
BAssign multiple Resolver services to different keys in the route's 'resolve' property
CUse multiple 'canActivate' guards to fetch data sequentially before route activation
DCall all data fetching methods inside the component's ngOnInit lifecycle hook
Step-by-Step Solution
Solution:
  1. Step 1: Understand multiple Resolvers

    Angular allows multiple Resolvers by assigning them to different keys in the 'resolve' object.
  2. Step 2: Evaluate options

    Assign multiple Resolver services to different keys in the route's 'resolve' property correctly describes this approach. Chain multiple Resolvers inside a single Resolver service and assign it to the route is incorrect because chaining inside one Resolver is manual and not standard. Use multiple 'canActivate' guards to fetch data sequentially before route activation confuses guards with Resolvers. Call all data fetching methods inside the component's ngOnInit lifecycle hook fetches data after navigation, not pre-fetching.
  3. Final Answer:

    Assign multiple Resolver services to different keys in the route's 'resolve' property -> Option B
  4. Quick Check:

    Multiple Resolvers use separate keys in 'resolve' [OK]
Quick Trick: Use separate keys in 'resolve' for multiple Resolvers [OK]
Common Mistakes:
  • Trying to chain Resolvers inside one service
  • Using guards instead of Resolvers for data fetching
  • Fetching data inside components instead of pre-fetching

Want More Practice?

15+ quiz questions · All difficulty levels · Free

Free Signup - Practice All Questions
More Angular Quizzes