import { Component , ComponentFactoryResolver , OnInit , Type , ViewChild , ViewContainerRef } from '@angular/core' ; import { PluginLoaderService } from './core/plugin-loader.service' ; @ Component ( { selector : 'app-root' , templateUrl : './app.component.html' , styleUrls : [ './app.component.css' ] } ) export class AppComponent implements OnInit { @ ViewChild ( 'targetRef' , { read : ViewContainerRef } ) vcRef : ViewContainerRef ; constructor ( private pluginLoader , private factoryResolver ) { } async ngOnInit ( ) { this . loadPlugin ( 'plugin1' ) ; } loadPlugin ( pluginName ) { this . pluginLoader . load ( pluginName ) . then ( ( component ) => { const compFactory = this . factoryResolver . resolveComponentFactory ( component ) ; this . vcRef . createComponent ( compFactory ) ; } ) ; } }