所以这是我的最终解决方案,它按我期望的方式工作。我把它贴在这里,以防有人掉进类似的兔子洞。
我仍在利用:
但不是customEvents.js
我之前提到的插件。
我已经完全从 Angular 包装器中获得了这个开箱即用的功能:
<xAxis (afterSetExtremes)="onAfterSetExtremesX($event)"></xAxis>
在我各自的 Angular 组件中,我设置了一个公共方法,如下所示:
public onAfterSetExtremesX (e: any) {
// I need context to this very component so I can bridge
// between Angular objects and classic jQuery techniques.
let self = this;
// Let's cherry-pick all WEEKLY record data from Highcharts setup.
let chartEvent0 = e.context.categories[0];
let chartEvent1 = e.context.categories[1];
let chartEvent2 = e.context.categories[2];
let chartEvent3 = e.context.categories[3];
let chartEvent4 = e.context.categories[4];
let chartEvent5 = e.context.categories[5];
let chartEvent6 = e.context.categories[6];
// Attach a click for these highcharts labels to invoke the component's method.
$('#label-single-0, #label-multiple-0').on('click', function(){
self.childModal.showModal(chartEvent0);
});
$('#label-single-1, #label-multiple-1').on('click', function(){
self.childModal.showModal(chartEvent1);
});
$('#label-single-2, #label-multiple-2').on('click', function(){
self.childModal.showModal(chartEvent2);
});
$('#label-single-3, #label-multiple-3').on('click', function(){
self.childModal.showModal(chartEvent3);
});
$('#label-single-4, #label-multiple-4').on('click', function(){
self.childModal.showModal(chartEvent4);
});
$('#label-single-5, #label-multiple-5').on('click', function(){
self.childModal.showModal(chartEvent5);
});
$('#label-single-6, #label-multiple-6').on('click', function(){
self.childModal.showModal(chartEvent6);
});
}
jQuery 可以选择 HTML 元素,因为它们最终被绘制到 Axis 上下文中,并且我将其桥接到一个名为的本地范围变量self
- 该变量是this
对该组件中定义的 Angular 对象的引用。