import { Directive , ViewContainerRef , ComponentFactoryResolver , Input } from '@angular/core' ; import { Spots } from './spots.module' ; @ Directive ( { selector : '[generic-spot]' } ) export class GenericSpotDirective { @ Input ( ) public spotType : string ; @ Input ( ) public spotData ; constructor ( private viewContainer , private cfResolver ) { } ngOnChanges ( change ) { if ( change ) { this . viewContainer . clear ( ) ; const componentClass = Spots . find ( component => component . ref === this . spotType ) ; const spotComponentFactory = this . cfResolver . resolveComponentFactory ( componentClass ) ; const spotComponent = this . viewContainer . createComponent ( spotComponentFactory ) ; spotComponent . instance [ 'data' ] = this . spotData ; } } }