Skip to content

Instantly share code, notes, and snippets.

Embed
What would you like to do?
export class AppPreloadingStrategy implements PreloadingStrategy {
preload(route: Route, load: Function): Observable<any> {
const loadRoute = (delay) => delay
? timer(150).pipe(flatMap(_ => load()))
: load();
return route.data && route.data.preload
? loadRoute(route.data.delay)
: of(null);
}
}
@vrkansagara

This comment has been minimized.

Copy link

@vrkansagara vrkansagara commented Oct 24, 2018

ERROR in src/app/AppPreloadingStrategy.ts(15,22): error TS2339: Property 'data' does not exist on type 'Route'.
src/app/AppPreloadingStrategy.ts(15,36): error TS2339: Property 'data' does not exist on type 'Route'.
src/app/AppPreloadingStrategy.ts(16,31): error TS2339: Property 'data' does not exist on type 'Route'.

ERROR in src/app/AppPreloadingStrategy.ts(15,22): error TS2339: Property 'data' does not exist on type 'Route'.
src/app/AppPreloadingStrategy.ts(15,36): error TS2339: Property 'data' does not exist on type 'Route'.
src/app/AppPreloadingStrategy.ts(16,31): error TS2339: Property 'data' does not exist on type 'Route'

@AckerApple

This comment has been minimized.

Copy link

@AckerApple AckerApple commented May 6, 2019

Where do I gettimer, flatMap, and of from? I've not worked with these before and I see no import statement.

rxjs? lodash?

May I recommend when making example code, please use universally understood code without extra implicit code

@dinopascale

This comment has been minimized.

Copy link

@dinopascale dinopascale commented Jun 7, 2019

Where do I gettimer, flatMap, and of from? I've not worked with these before and I see no import statement.

rxjs? lodash?

May I recommend when making example code, please use universally understood code without extra implicit code

This example describes an advanced Angular strategy and assumes that the reader knows at least rxJS

@joelsulca

This comment has been minimized.

Copy link

@joelsulca joelsulca commented Dec 27, 2019

Where do I gettimer, flatMap, and of from? I've not worked with these before and I see no import statement.

rxjs? lodash?

May I recommend when making example code, please use universally understood code without extra implicit code

import {PreloadingStrategy, Route} from '@angular/router';
import {Observable, of, timer} from 'rxjs';
import {flatMap} from 'rxjs/operators';

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
You can’t perform that action at this time.