我在Angular应用程序中有以下格式化程序函数:
dataLabels: [{
enabled: true,
formatter: function () {
return Math.round(this.point.y * 10000) / 100 + "%";
}]
我想访问格式化程序函数中的Angular组件级属性。我可以通过使用.bind(this)
来实现这一点,但是绑定后this.point.y
不再可访问。
dataLabels: [{
enabled: true,
formatter: function () {
return Math.round(this.point.y * 10000) / 100 + "%"; //// This does not work.
}.bind(this)]
绑定到这个之后,我如何访问点y的值?
要访问this.componentLevelProperty,可以使用一个提供箭头功能的作用域。
dataLabels: {
enabled: true,
formatter: () => {
console.log(this.somePropertyOnTheAppComponent);
return 'update';
},
},
演示