license import { Directive , ElementRef , Input , OnChanges , OnDestroy , OnInit , SimpleChanges } from '@angular/core' ; import { Chart } from './chart' ; import { MapChart } from './mapchart' ; import { StockChart } from './stockchart' ; import { HighchartsGantt } from './highcharts-gantt' ; @ Directive ( { selector : '[chart]' } ) export class ChartDirective implements OnInit , OnDestroy , OnChanges { @ Input ( ) chart : Chart | StockChart | MapChart | HighchartsGantt ; constructor ( private el ) { } ngOnChanges ( changes ) { if ( ! changes . chart . isFirstChange ( ) ) { this . destroy ( ) ; this . init ( ) ; } } ngOnInit ( ) { this . init ( ) ; } ngOnDestroy ( ) { this . destroy ( ) ; } private init ( ) { if ( this . chart instanceof Chart || this . chart instanceof StockChart || this . chart instanceof MapChart || this . chart instanceof HighchartsGantt ) { this . chart . init ( this . el ) ; } } private destroy ( ) { if ( this . chart instanceof Chart || this . chart instanceof StockChart || this . chart instanceof MapChart || this . chart instanceof HighchartsGantt ) { this . chart . destroy ( ) ; } } }