0
0
Angularframework~20 mins

Preloading strategies in Angular - Practice Problems & Coding Challenges

Choose your learning style9 modes available
Challenge - 5 Problems
🎖️
Angular Preloading Master
Get all challenges correct to earn this badge!
Test your skills under time pressure!
component_behavior
intermediate
2:00remaining
How does Angular's PreloadAllModules strategy behave?
Consider an Angular app using the PreloadAllModules strategy. What happens after the app's initial load?
ALazy-loaded modules load only if the user clicks a preload button.
BOnly the first lazy-loaded module is loaded after the app starts; others load on demand.
CNo lazy-loaded modules load until the user navigates to their routes.
DAll lazy-loaded modules start loading immediately after the app finishes initial rendering.
Attempts:
2 left
💡 Hint
Think about what 'preload all' means for modules that are lazy-loaded.
state_output
intermediate
2:00remaining
What is the effect of NoPreloading strategy on lazy-loaded modules?
If an Angular app uses the NoPreloading strategy, when do lazy-loaded modules load?
AAll lazy-loaded modules load immediately after app startup.
BLazy-loaded modules load only when the user navigates to their routes.
CLazy-loaded modules never load, causing navigation errors.
DLazy-loaded modules load randomly at intervals.
Attempts:
2 left
💡 Hint
Consider the default behavior without preloading.
📝 Syntax
advanced
2:00remaining
Identify the correct way to enable PreloadAllModules in Angular Router
Which code snippet correctly sets the router to use PreloadAllModules?
ARouterModule.forRoot(routes, { preloadingStrategy: PreloadAllModules })
BRouterModule.forRoot(routes, { preloadingStrategy: 'PreloadAllModules' })
CRouterModule.forRoot(routes, { preloadStrategy: PreloadAllModules })
DRouterModule.forRoot(routes, { preloadingStrategy: new PreloadAllModules() })
Attempts:
2 left
💡 Hint
Check the exact property name and value type for preloadingStrategy.
🔧 Debug
advanced
2:30remaining
Why does a custom preloading strategy fail to preload modules?
A developer wrote a custom preloading strategy but finds no modules preload. What is a common mistake causing this?
Angular
import { Observable, of } from 'rxjs';
import { PreloadingStrategy, Route } from '@angular/router';

export class CustomPreloadingStrategy implements PreloadingStrategy {
  preload(route: Route, load: () => Observable<any>): Observable<any> {
    if (route.data && route.data['preload']) {
      return load();
    } else {
      return of(null);
    }
  }
}

// In routing module:
RouterModule.forRoot(routes, { preloadingStrategy: CustomPreloadingStrategy })
AThe preload method must return a Promise, not an Observable.
BThe CustomPreloadingStrategy class must extend PreloadAllModules to work.
CThe routes lack the 'data: { preload: true }' property to trigger preloading.
DThe preloadingStrategy option must be a string, not a class.
Attempts:
2 left
💡 Hint
Check what the preload method checks in the route data.
🧠 Conceptual
expert
3:00remaining
Why choose a custom preloading strategy over built-in ones?
Which reason best explains why an Angular app might use a custom preloading strategy instead of NoPreloading or PreloadAllModules?
ATo selectively preload only certain modules based on app logic or user roles.
BBecause PreloadAllModules causes syntax errors in Angular 17+.
CTo disable lazy loading entirely and load all modules eagerly.
DBecause NoPreloading preloads all modules immediately, causing delays.
Attempts:
2 left
💡 Hint
Think about control and flexibility in loading modules.