【问题标题】:Html2canvas + Angular2 : Rendering an element and appending the canvas to the body?Html2canvas + Angular2:渲染元素并将画布附加到正文?
【发布时间】:2017-03-10 17:12:52
【问题描述】:

我正在尝试在我的 angular2 项目中使用 html2canvas,我将创建一个元素并将画布附加到正文,如下所述:

let newDiv = document.createElement("div"); 
let newContent = document.createTextNode("Hi there and greetings!"); 
newDiv.appendChild(newContent); 
html2canvas(newDiv).then(function(canvas) {
    document.body.appendChild(canvas);
});

但我收到以下错误:

异常:未捕获(承诺中):TypeError:无法读取属性 null TypeError 的“removeAttribute”:无法读取属性 'removeAttribute' of null

有什么办法解决这个错误吗?

谢谢,

【问题讨论】:

    标签: angular html2canvas


    【解决方案1】:

    您必须安装类型定义并将其导入您的项目:

    npm install --save @types/html2canvas
    

    【讨论】:

    • 已经用过 "@types/html2canvas": "^0.5.33" & "html2canvas": "^0.5.0-beta4",
    • 供参考,渲染document.body时没有发现错误,我的问题是如何用“document.createElement”创建一个元素并渲染它
    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2021-11-09
    • 2016-10-03
    • 2016-02-03
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多