作者热门文章
- html - 出于某种原因,IE8 对我的 Sass 文件中继承的 html5 CSS 不友好?
- JMeter 在响应断言中使用 span 标签的问题
- html - 在 :hover and :active? 上具有不同效果的 CSS 动画
- html - 相对于居中的 html 内容固定的 CSS 重复背景?
我正在构建一个使用 Angular 7 的项目。我目前正在尝试实现签名并将签名图像保存在数据库中。所以我选择“angular2-signaturepad”包来实现签名。在抽签完成之前它工作正常。签名抽奖完成后,我想保存图像。但它在绘制完成后显示错误“无法读取未定义的属性‘toDataURL’”。
在html文件中
<signature-pad [options]='signaturePadOptions' (onBeginEvent)="drawBegin()" (onEndEvent)="drawComplete()"></signature-pad>
在ts文件中
import { SignaturePad } from "angular2-signaturepad/signature-pad";
内部初始化
@ViewChild('SignaturePad') signaturePad: SignaturePad;
public SignaturePadOptions = {
'minWidth':2,
'penColor':'rgb(66,133,244)',
'backgroundColor':'rgb(255,255,255)',
'canvasWidth':450,
'canvasHeight':150,
};
public drawBegin(): void {
console.log('Begin Drawing');
}
public drawComplete(): void {
let signature = this.signaturePad.toDataURL('image/jpeg', 0.5);
console.log(signature);
}
}```
I expect the output should be the base url image name while console the result. But it is showing error "ERROR TypeError: Cannot read property 'toDataURL' of undefined".
最佳答案
我在 ionic 4 中遇到这样的问题,因为 Ionic 在 View 完成渲染之前执行构造函数。看看这个可能有帮助 https://github.com/szimek/signature_pad/issues/412
关于angular - 如何在 angular2-signaturePad 中修复 "Cannot read property ' toDataURL' of undefined",我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/57204438/
我是一名优秀的程序员,十分优秀!