Skip to content

Instantly share code, notes, and snippets.

@phenomnomnominal
Last active March 10, 2019 11:11
Show Gist options
  • Save phenomnomnominal/1533e03f8d9dd317f7f2a11ab77bfbb1 to your computer and use it in GitHub Desktop.
Save phenomnomnominal/1533e03f8d9dd317f7f2a11ab77bfbb1 to your computer and use it in GitHub Desktop.
export const ROUTES = new InjectionToken<Route[][]>('ROUTES');
export class RouterConfigLoader {
// ...
load(parentInjector: Injector, route: Route): Observable<LoadedRouterConfig> {
// ...
const moduleFactory$ = this.loadModuleFactory(route.loadChildren !);
// ...
}
private loadModuleFactory(loadChildren: LoadChildren): Observable<NgModuleFactory<any>> {
if (typeof loadChildren === 'string') {
return from(this.loader.load(loadChildren));
} else {
return wrapIntoObservable(loadChildren()).pipe(mergeMap((t: any) => {
if (t instanceof NgModuleFactory) {
return of (t);
} else {
return from(this.compiler.compileModuleAsync(t));
}
}));
}
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment