2017-01-16 10 views
2

Angular 2プロジェクトでは、バージョン番号0.5.0betaのhtml2canvasモジュールをインストールしました。私はnpm startコマンドを実行すると、この後html2canvasコールバックOnrenderedがAngular 2で機能しない

html2canvas (document.getElementById('exportthis'), { 
         onrendered : function (canvas) { 

、私が書かれていることを、私のpdfDownload方法で次に

import html2canvas from 'html2canvas'; 

はその後、私のTSファイルで、私はそれをインポートしてい

onrenderedはhtml2canvasOptionsで定義されているプロパティではありません。

誰でもこの問題の解決に手伝ってもらえますか? 私はAngle 2とhtml2canvasで作業しているのは初めてです。

+0

ようこそを変更する必要があります!良い質問をするのを助けるために私たちの[SO Question Checklist](http://meta.stackoverflow.com/questions/260648/stack-overflow-question-checklist)をよく読んで、良い答えを得てください。 –

答えて

3

私は同様の問題に直面しました。

html2canvas以外のオプションオブジェクトを関数呼び出しとして宣言することで解決できました。何かのようなもの。これは、TSコンパイラが内部の渡されたオプションオブジェクトをチェックするのを防ぎます。

var obj = { 
    onrendered: function (canvas) { 
    var imgData = canvas.toDataURL("image/png"); 
    } 
}; 
    html2canvas(document.getElementById("exportthis"), obj); 

EDIT:2.4.0へtypescriptですのアップグレード後
、エラー

TS2559: Type '{ onrendered: (canvas: any) => void; }' has no properties in common with type 'Html2CanvasOptions'. 

の下に取得する場合、その後のログのようなHtml2CanvasOptionsプロパティのいずれかを追加します:偽

obj = { 
    onrendered: function (canvas) { 
    var imgData = canvas.toDataURL("image/png"); 
    }, 
    logging: false 
}; 
    html2canvas(document.getElementById("exportthis"), obj); 
+0

は魅力的に働いた。ありがとう! – Julian

6

あなたはhtml2canvas 0.5バージョンを使っています。 onrenderedは、0.4以前のバージョンで使用されていました。 html2canvas 0.5がPromisesを使用するように書き換えられました。 あなたは、スタックオーバーフローに

html2canvas (document.getElementById('exportthis'), { onrendered : function (canvas) {

html2canvas(document.getElementById('exportthis')).then(function (canvas) { 
関連する問題