import { Component , ComponentFactoryResolver , Input , OnInit , ReflectiveInjector , ViewChild , ViewContainerRef } from '@angular/core' ; import { PendingApprovalActionsComponent } from "../pending-approval-actions/pending-approval-actions.component" ; import { RequestsActionsComponent } from "../requests-actions/requests-actions.component" ; import { MembersActionsComponent } from "../members-actions/members-actions.component" ; @ Component ( { selector : 'app-dynamic-component-loader' , templateUrl : './dynamic-component-loader.component.html' , styleUrls : [ './dynamic-component-loader.component.scss' ] , entryComponents : [ PendingApprovalActionsComponent , RequestsActionsComponent , MembersActionsComponent ] } ) export class DynamicComponentLoaderComponent implements OnInit { public _component ; constructor ( private resolver ) { } @ ViewChild ( 'dynamicComponentContainer' , { read : ViewContainerRef } ) dynamicComponentContainer : ViewContainerRef ; @ Input ( ) params ; @ Input ( ) set component ( component ) { let inputProviders = this . params ; let resolvedInputs = ReflectiveInjector . resolve ( inputProviders ) ; let injector = ReflectiveInjector . fromResolvedProviders ( resolvedInputs , this . dynamicComponentContainer . parentInjector ) ; let factory = this . resolver . resolveComponentFactory ( component ) ; let componentInner = factory . create ( injector ) ; this . dynamicComponentContainer . insert ( componentInner . hostView ) ; this . _component = componentInner ; } ngOnInit ( ) { } }