2017-06-25 5 views
0

MyHighChartComponent.tsどのようにどのように内部の高チャートのクリックイベントからtypescriptです関数を呼び出すために

export class MyHighChartComponent { 
    highchartsConfiguration: any = { 
     chart: { 
      events: { 
       click(e) { 
        if (!($(event.target)[0].textContent)) { 
         console.log('clicked'); //this is printing 
         this.drillDown(); // how to call typescript function here? 
        } 
       }, 
      }, 
     } 
    }; 

    drillDown() { 
     console.log('drill down method called'); 
    } 
} 

ハイチャートのクリックイベント内typescriptです関数を呼び出すには? TypeError例外:

は、私は、エラーの下に

エラー・スタックを取得していますthis.drillDownisない機能

+0

コードが有効のjs/tsの:) – toskv

+0

@toskvそれが有効だが、それを必要としないため、私は全体のコードを投稿していないことを確認します。ちょうどドリルダウンメソッドを呼び出す方法を知りたかった –

+0

あなたが投稿したコードは有効なJavaScriptコードではありません..クリック(e){}は有効ではありませんjs ..あなたが欠けているのはクリックハンドラそれで全部です。 – toskv

答えて

1

をあなたはクリックハンドラ内で同じコンテキスト(これを)維持するために、矢印機能を使用する必要があります。

それは次のようになります。

最初
export class MyHighChartComponent { 
    highchartsConfiguration: any = { 
     chart: { 
      events: { 
       click : (e) => { 
        if (!($(event.target)[0].textContent)) { 
         console.log('clicked'); //this is printing 
         this.drillDown(); // how to call typescript function here? 
        } 
       }, 
      }, 
     } 
    }; 

    drillDown() { 
     console.log('drill down method called'); 
    } 
} 
+0

ありがとうございました。その働き –

関連する問題