Jump into concepts and practice - no test required
or
Recommended
Test this pattern10 questions across easy, medium, and hard to know if this pattern is strong
Recall & Review
beginner
What is the purpose of preloading strategies in Angular routing?
Preloading strategies help load lazy-loaded modules in the background after the app starts, improving user experience by reducing wait times when navigating.
Click to reveal answer
beginner
Name the two built-in preloading strategies Angular provides.
Angular provides NoPreloading (default, no modules preloaded) and PreloadAllModules (all lazy modules preload after app start).
Click to reveal answer
beginner
How do you enable the PreloadAllModules strategy in Angular?
In the RouterModule.forRoot() method, pass { preloadingStrategy: PreloadAllModules } as the second argument.
Click to reveal answer
intermediate
What is a custom preloading strategy in Angular?
A custom preloading strategy is a user-defined service implementing the PreloadingStrategy interface to control which modules preload based on custom logic.
Click to reveal answer
intermediate
Why might you choose a custom preloading strategy over the built-in ones?
To preload only specific modules based on conditions like user roles, network speed, or app state, optimizing performance and resource use.
Click to reveal answer
Which Angular preloading strategy loads all lazy modules immediately after app start?
ACustomPreloading
BNoPreloading
CPreloadAllModules
DLazyLoadingOnly
✗ Incorrect
PreloadAllModules loads all lazy modules in the background after the app starts, improving navigation speed.
What is the default preloading strategy in Angular routing?
ANoPreloading
BPreloadAllModules
CCustomPreloading
DEagerLoading
✗ Incorrect
NoPreloading is the default, meaning lazy modules load only when the user navigates to them.
How do you specify a preloading strategy in Angular routing configuration?
AIn the RouterModule.forRoot() options
BIn the module imports array
CIn the component decorator
DIn the main.ts file
✗ Incorrect
You set the preloading strategy by passing { preloadingStrategy: ... } to RouterModule.forRoot().
What interface must a custom preloading strategy implement?
AOnInit
BResolve
CCanActivate
DPreloadingStrategy
✗ Incorrect
Custom preloading strategies implement the PreloadingStrategy interface to define preload behavior.
Which scenario best fits using a custom preloading strategy?
APreload all modules regardless of conditions
BPreload modules based on user permissions
CLoad modules only on navigation
DNever preload any modules
✗ Incorrect
Custom strategies allow preloading modules selectively, such as based on user permissions or network conditions.
Explain what preloading strategies are in Angular and why they matter.
Think about how apps load parts in the background to be ready faster.
You got /3 concepts.
Describe how to implement a custom preloading strategy in Angular.
Focus on the interface and where to configure it.
You got /3 concepts.
Practice
(1/5)
1. What is the main purpose of preloading strategies in Angular?
easy
A. To load lazy modules in the background to improve navigation speed
B. To prevent any modules from loading until explicitly requested
C. To compile all modules at build time for faster startup
D. To automatically update Angular to the latest version
Solution
Step 1: Understand lazy loading in Angular
Lazy loading delays loading modules until needed, which can slow navigation initially.
Step 2: Role of preloading strategies
Preloading strategies load lazy modules in the background after app startup to speed up future navigation.
Final Answer:
To load lazy modules in the background to improve navigation speed -> Option A
Quick Check:
Preloading = background loading for faster navigation [OK]
Hint: Preloading means loading modules quietly before needed [OK]
Common Mistakes:
Confusing preloading with eager loading
Thinking preloading disables lazy loading
Assuming preloading updates Angular versions
2. Which of the following is the correct way to enable preloading of all lazy modules in Angular routing?
easy
A. RouterModule.forRoot(routes, { preloadingStrategy: PreloadAllModules })
B. RouterModule.forRoot(routes, { preload: true })
C. RouterModule.forRoot(routes, { lazyLoad: true })
D. RouterModule.forRoot(routes, { preloadingStrategy: NoPreloading })
B. Using string syntax for loadChildren is deprecated; should use dynamic import
C. Preloading strategy must be NoPreloading when using lazy loading
D. RouterModule.forRoot should not have a second argument
Solution
Step 1: Check loadChildren syntax
The string syntax ('./dashboard/dashboard.module#DashboardModule') is deprecated in Angular; dynamic import is required.
Step 2: Confirm preloading strategy and other options
Preloading strategy can be used with lazy loading; no error there. 'pathMatch' is optional here.
Final Answer:
Using string syntax for loadChildren is deprecated; should use dynamic import -> Option B
Quick Check:
Use dynamic import() for loadChildren [OK]
Hint: Use dynamic import() syntax for loadChildren [OK]
Common Mistakes:
Using old string syntax for loadChildren
Thinking preloading strategy conflicts with lazy loading
Assuming pathMatch is mandatory for all routes
5. You want to preload only the 'admin' module but not the 'user' module in your Angular app. Which approach correctly implements this custom preloading strategy?
hard
A. Set preloadingStrategy to NoPreloading and preload 'admin' module eagerly
B. Use PreloadAllModules and then lazy load 'user' module manually
C. Create a class implementing PreloadingStrategy that preloads only routes with data.preload = true
D. Mark 'admin' module as eager loaded and 'user' as lazy loaded without preloading
Solution
Step 1: Understand custom preloading strategy
Angular allows creating a class implementing PreloadingStrategy to control which modules preload.
Step 2: Use route data property to select modules
By checking data.preload flag in routes, the strategy can preload only selected modules like 'admin'.
Final Answer:
Create a class implementing PreloadingStrategy that preloads only routes with data.preload = true -> Option C
Quick Check:
Custom strategy uses data.preload flag [OK]
Hint: Use data.preload flag with custom PreloadingStrategy [OK]
Common Mistakes:
Using PreloadAllModules when selective preload is needed
Trying to preload modules eagerly without strategy