如何在禁用后呈现 ng2 图表

How to render ng2 chart after it's disabled

我有一个在初始化时被禁用的条形图

  <div style="display: block" *ngIf="showBar">
  <canvas baseChart height="75"
          [data]="barChartData"
          [labels]="barChartLabels"
          [chartType]="'bar'"
          (chartHover)="chartHovered($event)"
          (chartClick)="chartClicked($event)"></canvas>
</div>

栏-graph.component.ts 文件:

export class BarGraphComponent implements OnInit {
showBar: boolean;
ngOnInit() {
this.showBar = false;
}

我想使用 switch 语句在 app.components.ts 文件中启用此图表(更改取决于从先前图表传递的内容)。但是在应用程序 component.ts 文件中,如果我执行 this.showBar = true(使用发射器)它仍然不起作用。任何指导将不胜感激。

今天早上解决了这个问题。而不是在 bar-graph.component.html 中声明 *ngIf。它应该在 app.component.html

中声明
<app-bar-graph *ngIf="showBarGraph" [config]="barConfig" (notify)="onNotify($event)"></app-bar-graph>

然后在app.component.ts

里面
export class AppComponent implements OnInit {
showBarGraph: boolean;
... logic goes here ....
this.showBarGraph = true;

希望这对以后的人有所帮助