html2canvas in angular 4

痴心易碎 提交于 2019-12-03 07:41:13
Mam's
pdfDownload() {
    let self = this;//use this variable to access your class members inside then().
    html2canvas(document.body).then(canvas => {
        var imgData = canvas.toDataURL("image/png");
        self.AddImagesResource(imgData);
        document.body.appendChild(canvas);
   });
}

When providing the callback for a promise in Angular, you should use an arrow function, rather than an anonymous function. Arrow functions bind to the current context correctly, so the function you are trying to call will be accessible.

Try this instead:

pdfDownload() {
    html2canvas(document.body).then(canvas => {
        var imgData = canvas.toDataURL("image/png");
        this.AddImagesResource(imgData);
        document.body.appendChild(canvas);
    });
}

Make sure to import the script under the scripts list in angular-cli.json

"scripts": [
"../node_modules/html2canvas/dist/html2canvas.min.js"
]

And in the class as:

import * as html2canvas from "html2canvas"
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!