I am unable to add to the scope of formatter
function the class’s scope.
I would like to call
pointFormatter
with “this” (the callback scope of formatter in addition to the class’s scope since there is a variable that is necessary for me) but when I use the arrow function or use .bind(this) the scope gets replaced completely with the class’s scope and then I can’t access this.x (I get an error: Property ‘x’ does not exist on type ‘MyService’
Please note, this.urlService
is in MyService’s scope and this is why I need access to the class’s scope.
formatter: function (tooltip: Tooltip) {
const date = new Date(this.x);
const pointString = tooltip.options.pointFormatter.call(this);
return `<div>${moment(date).format('MMM Do YYYY')}<br />${pointString}</div>`;
},
pointFormatter: function (): string {
const selectedDate = new Date(Number(this.x));
return `<a target="_blank" href=${this.urlService.myUrl}?time=selectedDate>Total Websites: ${this.y}</a>`;
}
Bottom line- I’m trying to understand how I can get access to the callback function scope AND the surrounding class’s scope. Please let me know if I wasn’t clear and thank you.