import { AfterViewInit, Directive, ElementRef, Input } from '@angular/core'; import { ECharts, init } from 'echarts'; @Directive({ selector: '[echarts]' }) export class EchartsDirective implements AfterViewInit { constructor( private _elementRef: ElementRef ) { } ngAfterViewInit(): void { this._echarts = init(this._elementRef.nativeElement); if (this._options) { this._echarts.setOption(this._options); } } @Input() public set echarts(options: any) { if (this._options = options) { if (this._echarts) { this._echarts.setOption(options); } } } private _echarts: ECharts; private _options: any; }