Angular6:@ViewChildren和HighCharts

时间:2019-04-02 15:30:21

标签: angular highcharts

我试图使用highcharts在同一个组件中动态创建多个图表。因此,在模板中带有* ngFor的情况下,我试图使用@ViewChildren批注。

当我只想显示一个图表时,我只需要使用@ViewChild和 在定义图表的this.chart = chart(this.chartTarget.nativeElement,this.options);之后option

我尝试过的事情:

component.ts

@ViewChildren('chartTarget') chartTargets: QueryList<ElementRef>;
public defects: Array<Defect>;

displayChart() {
    this.defects.forEach((def: Defect) => {
        this.option = {...}
        this.chart = chart(this.chartTargets.toArray()[0].nativeElement,this.options);
    }
}

我也尝试过:

ngAfterViewChecked() {
    this.chart = chart(this.chartTargets.toArray()[0].nativeElement,this.options);
}

component.html

<div #chartTarget *ngFor="let def of defects | keyvalue"></div>

我收到此错误:

Cannot read property 'nativeElement' of undefined

预先感谢

0 个答案:

没有答案