Complete the code to enable preloading of all lazy-loaded modules in Angular.
RouterModule.forRoot(routes, { preloadingStrategy: [1] })The PreloadAllModules strategy tells Angular to preload all lazy-loaded modules after the app loads.
Complete the code to import the Angular preloading strategies module.
import { [1] } from '@angular/router';
You import PreloadAllModules from @angular/router to use it as a preloading strategy.
Fix the error in the code to correctly set the preloading strategy to no preloading.
RouterModule.forRoot(routes, { preloadingStrategy: [1] })NoPreloading disables preloading of lazy-loaded modules.
Fill both blanks to create a custom preloading strategy class that implements Angular's PreloadingStrategy interface.
export class CustomPreloadingStrategy implements [1] { preload(route: Route, load: () => Observable<any>): Observable<any> { if (route.data && route.data.[2]) { return load(); } else { return of(null); } } }
The class must implement PreloadingStrategy and define the preload method.
Fill all three blanks to configure the router with a custom preloading strategy and enable preloading for routes with data property 'preload: true'.
RouterModule.forRoot(routes, { preloadingStrategy: [1] })
const routes: Routes = [
{
path: 'feature',
loadChildren: () => import('./feature/feature.module').then(m => m.FeatureModule),
data: { [2]: true }
},
{
path: 'other',
loadChildren: () => import('./other/other.module').then(m => m.OtherModule),
data: { [3]: false }
}
];Use CustomPreloadingStrategy as the preloading strategy. The routes use the preload data property to control preloading.