Skip to content

Instantly share code, notes, and snippets.

@ShilpaLalwani
Last active April 27, 2020 09:06
Show Gist options
  • Save ShilpaLalwani/aa95da5d1094006427a9a04c99dcca8e to your computer and use it in GitHub Desktop.
Save ShilpaLalwani/aa95da5d1094006427a9a04c99dcca8e to your computer and use it in GitHub Desktop.
import {
Injectable,
ComponentFactoryResolver,
ViewContainerRef
} from '@angular/core';
import { from } from 'rxjs';
import { map } from 'rxjs/operators';
export interface ComponentLoader {
loadChildren: () => Promise<any>;
}
@Injectable({
providedIn: 'root'
})
export class AppService {
constructor(private cfr: ComponentFactoryResolver) {}
resolveComponent(vcr: ViewContainerRef, cl: ComponentLoader) {
return from(cl.loadChildren()).pipe(
map((component: any) => this.cfr.resolveComponentFactory(component)),
map(componentFactory => vcr.createComponent(componentFactory))
);
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment