Chartjs-How to call a typescript arrow function and a javascript function in the same event

0👍

before using the chart in component assign this to some other variable like

var that=this

then in your chart

 onClick: function(evt){

      console.log(this);//<-- returns chart

   let   bar= () => {console.log(that)}; //<-- that should have your component refrence

  }

Stackblitz demo

2👍

What you’re doing with the bar and the colon in the function is that you’re trying to describe its type rather to declare it. So if you want to actually declare the function, do this:

onClick: function(evt) {

    console.log(this);//<-- returns chart

    let bar = () => { console.log(this) };
    bar();

    //console.log(document.getElementById('myChart'));
  }

if you want to describe and declare it, do this:

  onClick: function(evt) {

    console.log(this);//<-- returns chart

    let bar: () => void = () => { console.log(this) }; //<-- here I try to get this as component
    bar(); // <--doesnt work

    //console.log(document.getElementById('myChart'));
  }

Leave a comment