import { Component , Input , ViewContainerRef , OnInit , ComponentFactoryResolver } from '@angular/core' ; import { GadgetInstanceService } from './grid.service' ; import { GadgetFactory } from '../add-gadget/gadget-factory' ; @ Component ( { selector : 'app-grid-cell' , template : '' } ) export class CellComponent implements OnInit { @ Input ( ) gadgetType : string ; @ Input ( ) gadgetConfig : any ; @ Input ( ) gadgetInstanceId : number ; @ Input ( ) gadgetTags : Array < any > ; constructor ( private viewContainerRef , private cfr , private gadgetInstanceService ) { } ngOnInit ( ) { const component = GadgetFactory . getComponentType ( this . gadgetType ) ; let compFactory = { } ; let gadgetRef = { } ; if ( component ) { compFactory = this . cfr . resolveComponentFactory ( component ) ; gadgetRef = this . viewContainerRef . createComponent ( compFactory ) ; gadgetRef . instance . configureGadget ( this . gadgetInstanceId , this . gadgetConfig , this . gadgetTags ) ; this . gadgetInstanceService . addInstance ( gadgetRef ) ; } } }