AmCharts XY图表 - 如何在Angular中点击模式弹出窗口?

问题描述 投票:0回答:1

当用户点击数据点时,我们需要显示模态窗口。

我们的代码是:

  constructor(public dataservice: DataserviceService, private modalService: NgbModal, private router: Router) { }
  ...
  ...
  bullet.events.on("hit", function (ev) {
    console.log(ev.target._dataItem.dataContext);
    this.modalService.open(this.dialog);
  });
}

public showDialog() {
  this.modalService.open(this.dialog);
}

enter image description here我们能够在控制台中看到日志数据..但不是模态。我们怎么解决这个问题?

angular amcharts amcharts4
1个回答
1
投票

代码看起来很好,但正如@yurzui所说,问题在于此

bullet.events.on("hit", function (ev) {}

因为它将从另一个上下文调用,所以modalService在那里不可用。尝试使用箭头函数,以保留此上下文。要解决此问题,

bullet.events.on("hit", (ev) => {
    console.log(ev.target._dataItem.dataContext);
    this.modalService.open(this.dialog);
 });
© www.soinside.com 2019 - 2024. All rights reserved.