Last active
April 27, 2020 09:06
-
-
Save ShilpaLalwani/aa95da5d1094006427a9a04c99dcca8e to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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