我正在尝试在我的项目中包含的第三方库(highcharts)中的某个类中使用函数。
有些事情:
export class TrendPage {
...
functionToUse(){
this.top = someCalculation();
}
...
this.chart = Highcharts.chart(this.chartContainer, {
...
xAxis: {
events: {
afterSetExtremes: ()=> {
this.functionToUse()
}
}
},
...
有没有正确的方法呢?
解决方案我发现:
使用ngZone在区域范围之外运行函数,如在此答案中Angular2 - how to call component function from outside the app
答案 0 :(得分:0)
在
this.functionToUse()
"这"在函数的范围内,不能"见"对于外面的功能。你可以试试这个代码吗?
afterSetExtremes: ()=>
{
this.functionToUse()
}
小心,因为"事件"使用此匿名函数不能再使用变量。 (更多地搜索lambda / anonymous函数)